Skip to content

Instantly share code, notes, and snippets.

View Micky774's full-sized avatar

Meekail Zain Micky774

  • AMD
View GitHub Profile
@Micky774
Micky774 / benchmark.py
Created March 24, 2023 23:45
csr_polynomial benchmark
import numpy as np
from scipy import sparse as sp
def generate_data(n_samples, n_features, n_classes=2, X_density=1, y_sparse=False, dtype=np.float64, random_state=None):
rng = np.random.RandomState(random_state)
if X_density < 1:
X = sp.random(n_samples, n_features, format="csr", density=X_density, random_state=rng)
else:
X = np.round(rng.rand(n_samples,n_features)*50).astype(dtype)
y = np.round(rng.randint(n_classes,size=(n_samples,))).astype(dtype)
import numpy as np
from functools import partial
from time import perf_counter
from statistics import mean, stdev
from itertools import product
import csv
from pathlib import Path
from sklearn.neighbors import KNeighborsClassifier
results_path = 'local_artifacts/benchmarks/pwd_labels/predict_proba/large_wide/'
@Micky774
Micky774 / demo.pyx
Created December 29, 2022 01:02
Cython vtable workarounds
# Compile with annotated view to compare generated instructions
# and presence of `__pyx_vtabstruct_*`
from cython cimport final
# Typedef function pointer
ctypedef int (*f_type)(A)
# Ancestor, serves as interface/ABC
cdef class A:
cdef f_type func
@Micky774
Micky774 / benchmark.py
Created August 24, 2022 23:50
PWD predict proba benchmark
import numpy as np
import scipy.sparse as sp
def generate_data(n_samples, n_features, n_classes=2, X_density=1, y_sparse=False, dtype=np.float64, random_state=None):
rng = np.random.RandomState(random_state)
if X_density < 1:
X = sp.random(n_samples, n_features, format="csr", density=X_density, random_state=rng)
else:
X = np.round(rng.rand(n_samples,n_features)*50).astype(dtype)
y = np.round(rng.randint(n_classes,size=(n_samples,))).astype(dtype)
@Micky774
Micky774 / benchmark.py
Created August 24, 2022 22:28
PWD KNearestNeighbors.predict benchmarks
import numpy as np
import scipy.sparse as sp
def generate_data(n_samples, n_features, n_classes=2, X_density=1, y_sparse=False, dtype=np.float64, random_state=None):
rng = np.random.RandomState(random_state)
if X_density < 1:
X = sp.random(n_samples, n_features, format="csr", density=X_density, random_state=rng)
else:
X = np.round(rng.rand(n_samples,n_features)*50).astype(dtype)
y = np.round(rng.randint(n_classes,size=(n_samples,))).astype(dtype)
@Micky774
Micky774 / bench.py
Created August 4, 2022 17:43
PWD_Labels Benchmark
# %%
import numpy as np
import scipy.sparse as sp
def generate_data(n_samples, n_features, n_classes=2, X_density=1, y_sparse=False, dtype=np.float64, random_state=None):
rng = np.random.RandomState(random_state)
if X_density < 1:
X = sp.random(n_samples, n_features, format="csr", density=X_density, random_state=rng)
else:
X = np.round(rng.rand(n_samples,n_features)*50).astype(dtype)
@Micky774
Micky774 / knn_bench.py
Created June 21, 2022 23:11
Benchmark for knn classifier predict.
# %%
from functools import partial
from time import perf_counter
from statistics import mean, stdev
from itertools import product
import csv
from sklearn.neighbors import KNeighborsClassifier
import numpy as np
def make_data(n_samples, n_features, n_classes, n_outs, random_state=None):
@Micky774
Micky774 / trust_ng_tol_survey.py
Created June 20, 2022 18:49
Benchmarks for trust-ncg across various tol values, compared w/ current solvers.
import numpy as np
import pandas as pd
from sklearn.compose import ColumnTransformer
from sklearn.datasets import fetch_openml
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import OneHotEncoder, FunctionTransformer, StandardScaler, KBinsDiscretizer
from sklearn.model_selection import train_test_split
import joblib
@Micky774
Micky774 / gist:9f72b1d9532b1bc73b8aeac299276c77
Created June 14, 2022 16:41
assert_all_finite benchmark
# %%
import numpy as np
import scipy.sparse as sp
def generate_data(n_samples, n_features, X_density=1, y_sparse=False, dtype=np.float64, random_state=None):
rng = np.random.RandomState(random_state)
if X_density < 1:
X = sp.random(n_samples, n_features, format="csr", density=X_density, random_state=rng)
else:
X = np.round(rng.rand(n_samples,n_features)*50).astype(dtype)
@Micky774
Micky774 / logistic_regression_bench.py
Created June 9, 2022 14:57
Benchmark script for logistic regression
# %%
import numpy as np
import pandas as pd
from sklearn.compose import ColumnTransformer
from sklearn.datasets import fetch_openml
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import StandardScaler