Last active
August 11, 2021 15:54
-
-
Save ogrisel/f5d4f56421bcc25916d57d04a5448840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from subprocess import check_output | |
import threadpoolctl | |
from pprint import pprint | |
from time import perf_counter | |
from pathlib import Path | |
import sklearn | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.datasets import make_classification | |
from sklearn.model_selection import train_test_split | |
sklearn_path = Path(sklearn.__file__).parent | |
sklearn_version = sklearn.__version__ | |
sklearn_git_branch = ( | |
check_output( | |
f'(cd {sklearn_path} && git symbolic-ref --short HEAD) || echo ""', | |
shell=True, | |
) | |
.decode("utf-8") | |
.strip() | |
) | |
if sklearn_git_branch: | |
sklearn_version = f"{sklearn_version} (git: {sklearn_git_branch})" | |
print(f"sklearn {sklearn_version} at {sklearn_path}") | |
pprint(threadpoolctl.threadpool_info()) | |
train_size = int(1e5) | |
test_size = int(1e5) | |
n_features = 100 | |
X, y = make_classification( | |
n_samples=train_size + test_size, | |
n_features=n_features, | |
n_redundant=0, | |
n_informative=n_features, | |
random_state=0, | |
) | |
X_train, X_test, y_train, y_test = train_test_split( | |
X, | |
y, | |
train_size=train_size, | |
test_size=test_size, | |
random_state=0, | |
) | |
clf = KNeighborsClassifier(n_neighbors=10, n_jobs=1).fit(X_train, y_train) | |
tic = perf_counter() | |
y_pred = clf.predict(X_test) | |
toc = perf_counter() | |
assert y_pred.shape == y_test.shape | |
accuracy = np.mean(y_pred == y_test) | |
print( | |
f"n_samples_train: {X_train.shape[0]}, n_samples_test: {X_test.shape[0]}, acc:" | |
f" {accuracy:.3f}, duration: {toc - tic:.3f} s" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(intel) [ogrisel@marg002 ~]$ python -m sklearnex bench_knn.py | |
Intel(R) Extension for Scikit-learn* enabled (https://github.com/intel/scikit-learn-intelex) | |
fatal: not a git repository (or any parent up to mount point /) | |
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). | |
sklearn 0.24.2 at /scratch/ogrisel/miniforge3/envs/intel/lib/python3.8/site-packages/sklearn | |
[{'filepath': '/scratch/ogrisel/miniforge3/envs/intel/lib/libmkl_rt.so.1', | |
'internal_api': 'mkl', | |
'num_threads': 20, | |
'prefix': 'libmkl_rt', | |
'threading_layer': 'intel', | |
'user_api': 'blas', | |
'version': '2021.3-Product'}, | |
{'filepath': '/scratch/ogrisel/miniforge3/envs/intel/lib/libomp.so', | |
'internal_api': 'openmp', | |
'num_threads': 40, | |
'prefix': 'libomp', | |
'user_api': 'openmp', | |
'version': None}] | |
n_samples_train: 100000, n_samples_test: 100000, acc: 0.995, duration: 7.246 s | |
(sklearn-dev) [ogrisel@marg002 ~]$ python bench_knn.py | |
sklearn 1.0.dev0 (git: pairwise_aggregation_cython) at /home/parietal/ogrisel/code/scikit-learn/sklearn | |
[{'architecture': 'Sandybridge', | |
'filepath': '/scratch/ogrisel/miniforge3/envs/sklearn-dev/lib/libopenblasp-r0.3.17.so', | |
'internal_api': 'openblas', | |
'num_threads': 40, | |
'prefix': 'libopenblas', | |
'threading_layer': 'pthreads', | |
'user_api': 'blas', | |
'version': '0.3.17'}, | |
{'filepath': '/scratch/ogrisel/miniforge3/envs/sklearn-dev/lib/libomp.so', | |
'internal_api': 'openmp', | |
'num_threads': 40, | |
'prefix': 'libomp', | |
'user_api': 'openmp', | |
'version': None}] | |
n_samples_train: 100000, n_samples_test: 100000, acc: 0.995, duration: 52.746 s | |
(sklearn-0.24.2) [ogrisel@marg002 ~]$ python bench_knn.py | |
fatal: not a git repository (or any parent up to mount point /) | |
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). | |
sklearn 0.24.2 at /scratch/ogrisel/miniforge3/envs/sklearn-0.24.2/lib/python3.9/site-packages/sklearn | |
[{'architecture': 'Sandybridge', | |
'filepath': '/scratch/ogrisel/miniforge3/envs/sklearn-0.24.2/lib/libopenblasp-r0.3.17.so', | |
'internal_api': 'openblas', | |
'num_threads': 40, | |
'prefix': 'libopenblas', | |
'threading_layer': 'pthreads', | |
'user_api': 'blas', | |
'version': '0.3.17'}, | |
{'filepath': '/scratch/ogrisel/miniforge3/envs/sklearn-0.24.2/lib/libgomp.so.1.0.0', | |
'internal_api': 'openmp', | |
'num_threads': 40, | |
'prefix': 'libgomp', | |
'user_api': 'openmp', | |
'version': None}] | |
n_samples_train: 100000, n_samples_test: 100000, acc: 0.995, duration: 236.631 s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment