8000 MNT Add asv benchmark suite by jeremiedbb · Pull Request #17026 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT Add asv benchmark suite #17026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c5b9c22
move asv benchmark suite to scikit-learn
jeremiedbb Apr 23, 2020
1836d36
cln
jeremiedbb Apr 23, 2020
df88036
don't track cache
jeremiedbb Apr 24, 2020
55c8149
config
jeremiedbb Apr 24, 2020
3cf50b7
add doc
jeremiedbb Apr 30, 2020
ad13f0f
fix path
jeremiedbb Apr 30, 2020
6a21314
commited wrong stuff
jeremiedbb Apr 30, 2020
0b4a141
remove classmethod
jeremiedbb Apr 30, 2020
6c6d040
typo
jeremiedbb Apr 30, 2020
03f2a43
mention pandas doc
jeremiedbb Apr 30, 2020
24b3eb2
tst broken doc
jeremiedbb Apr 30, 2020
fd500b0
reorder
jeremiedbb May 5, 2020
d4dc45a
reorg
jeremiedbb May 11, 2020
7e32cb6
remove n_jobs from kmeans param names
jeremiedbb May 20, 2020
6b40ae8
origin -> upstream
jeremiedbb May 26, 2020
deb43c2
footnote
jeremiedbb May 26, 2020
d3924ae
docstrings
jeremiedbb May 26, 2020
913d850
docstrings
jeremiedbb May 26, 2020
2dc1246
virtualenv
jeremiedbb May 26, 2020
e6a7558
rename classes
jeremiedbb May 26, 2020
4accc0b
fix link
jeremiedbb May 26, 2020
405871b
pytest ignore asv_benchmarks
jeremiedbb Jun 3, 2020
dab34b8
env vars for config
jeremiedbb Jun 8, 2020
15342aa
env vars for config
jeremiedbb Jun 8, 2020
86210c7
pathlib
jeremiedbb Jun 9, 2020
e84d3d2
simpler data cache
jeremiedbb Jun 9, 2020
a3d82d2
simpler data cache
jeremiedbb Jun 10, 2020
56b4324
threadpoolctl in deps
jeremiedbb Jun 10, 2020
2392631
cln docstring
jeremiedbb Jun 10, 2020
7be77f3
add MiniBatchKMeans
jeremiedbb Jun 19, 2020
8f1ba71
empty commit for docs to build
NicolasHug Jul 27, 2020
898a333
Merge remote-tracking branch 'upstream/master' into add-asv-benchmarks
jeremiedbb Jul 28, 2020
4121522
additional instructions
jeremiedbb Jul 29, 2020
33de322
fix link
jeremiedbb Jul 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions asv_benchmarks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*__pycache__*
env/
html/
results/
scikit-learn/
benchmarks/cache/
162 changes: 162 additions & 0 deletions asv_benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
// The version of the config file format. Do not change, unless
// you know what you are doing.
"version": 1,

// The name of the project being benchmarked
"project": "scikit-learn",

// The project's homepage
"project_url": "scikit-learn.org/",

// The URL or local path of the source code repository for the
// project being benchmarked
"repo": "..",

// The Python project's subdirectory in your repo. If missing or
// the empty string, the project is assumed to be located at the root
// of the repository.
// "repo_subdir": "",

// Customizable commands for building, installing, and
// uninstalling the project. See asv.conf.json documentation.
//
// "install_command": ["python -mpip install {wheel_file}"],
// "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
// "build_command": [
// "python setup.py build",
// "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
// ],

// List of branches to benchmark. If not provided, defaults to "master"
// (for git) or "default" (for mercurial).
// "branches": ["master"], // for git
// "branches": ["default"], // for mercurial

// The DVCS being used. If not set, it will be automatically
// determined from "repo" by looking at the protocol in the URL
// (if remote), or by looking for special directories, such as
// ".git" (if local).
// "dvcs": "git",

// The tool to use to create environments. May be "conda",
// "virtualenv" or other value depending on the plugins in use.
// If missing or the empty string, the tool will be automatically
// determined by looking for tools on the PATH environment
// variable.
"environment_type": "conda",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should expect contributors to have conda

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the config file it's the default env. I added an explanation on how to use virtualenv instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we leave it empty?

If missing or the empty string, the tool will be automatically
// determined by looking for tools on the PATH environment
// variable


// timeout in seconds for installing any dependencies in environment
// defaults to 10 min
//"install_timeout": 600,

// the base URL to show a commit for the project.
"show_commit_url": "https://github.com/scikit-learn/scikit-learn/commit/",

// The Pythons you'd like to test against. If not provided, defaults
// to the current version of Python used to run `asv`.
// "pythons": ["3.6"],

// The list of conda channel names to be searched for benchmark
// dependency packages in the specified order
// "conda_channels": ["conda-forge", "defaults"]

// The matrix of dependencies to test. Each key is the name of a
// package (in PyPI) and the values are version numbers. An empty
// list or empty string indicates to just test against the default
// (latest) version. null indicates that the package is to not be
// installed. If the package to be tested is only available from
// PyPi, and the 'environment_type' is conda, then you can preface
// the package name by 'pip+', and the package will be installed via
// pip (with all the conda available packages installed first,
// followed by the pip installed packages).
//
"matrix": {
"numpy": [],
"scipy": [],
"cython": [],
"joblib": [],
"threadpoolctl": []
},

// Combinations of libraries/python versions can be excluded/included
// from the set to test. Each entry is a dictionary containing additional
// key-value pairs to include/exclude.
//
// An exclude entry excludes entries where all values match. The
// values are regexps that should match the whole string.
//
// An include entry adds an environment. Only the packages listed
// are installed. The 'python' key is required. The exclude rules
// do not apply to includes.
//
// In addition to package names, the following keys are available:
//
// - python
// Python version, as in the *pythons* variable above.
// - environment_type
// Environment type, as above.
// - sys_platform
// Platform, as in sys.platform. Possible values for the common
// cases: 'linux2', 'win32', 'cygwin', 'darwin'.
//
// "exclude": [
// {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows
// {"environment_type": "conda", "six": null}, // don't run without six on conda
// ],
//
// "include": [
// // additional env for python2.7
// {"python": "2.7", "numpy": "1.8"},
// // additional env if run on windows+conda
// {"platform": "win32", "environment_type": "conda", "python": "2.7", "libpython": ""},
// ],

// The directory (relative to the current directory) that benchmarks are
// stored in. If not provided, defaults to "benchmarks"
// "benchmark_dir": "benchmarks",

// The directory (relative to the current directory) to cache the Python
// environments in. If not provided, defaults to "env"
// "env_dir": "env",

// The directory (relative to the current directory) that raw benchmark
// results are stored in. If not provided, defaults to "results".
// "results_dir": "results",

// The directory (relative to the current directory) that the html tree
// should be written to. If not provided, defaults to "html".
// "html_dir": "html",

// The number of characters to retain in the commit hashes.
// "hash_length": 8,

// `asv` will cache results of the recent builds in each
// environment, making them faster to install next time. This is
// the number of builds to keep, per environment.
// "build_cache_size": 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's funny they went with json which specifically doesn't allow comments in the spec.


// The commits after which the regression search in `asv publish`
// should start looking for regressions. Dictionary whose keys are
// regexps matching to benchmark names, and values corresponding to
// the commit (exclusive) after which to start looking for
// regressions. The default is to start from the first commit
// with results. If the commit is `null`, regression detection is
// skipped for the matching benchmark.
//
// "regressions_first_commits": {
// "some_benchmark": "352cdf", // Consider regressions only after this commit
// "another_benchmark": null, // Skip regression detection altogether
// },

// The thresholds for relative change in results, after which `asv
// publish` starts reporting regressions. Dictionary of the same
// form as in ``regressions_first_commits``, with values
// indicating the thresholds. If multiple entries match, the
// maximum is taken. If no entry matches, the default is 5%.
//
// "regressions_thresholds": {
// "some_benchmark": 0.01, // Threshold of 1%
// "another_benchmark": 0.5, // Threshold of 50%
// },
}
1 change: 1 addition & 0 deletions asv_benchmarks/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Benchmark suite for scikit-learn using ASV"""
100 changes: 100 additions & 0 deletions asv_benchmarks/benchmarks/cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from sklearn.cluster import KMeans, MiniBatchKMeans

from .common import Benchmark, Estimator, Predictor, Transformer
from .datasets import _blobs_dataset, _20newsgroups_highdim_dataset
from .utils import neg_mean_inertia


class KMeansBenchmark(Predictor, Transformer, Estimator, Benchmark):
"""
Benchmarks for KMeans.
"""

param_names = ['representation', 'algorithm', 'init']
params = (['dense', 'sparse'], ['full', 'elkan'], ['random', 'k-means++'])

def setup_cache(self):
super().setup_cache()

def make_data(self, params):
representation, algorithm, init = params

if representation == 'sparse':
data = _20newsgroups_highdim_dataset(n_samples=8000)
else:
data = _blobs_dataset(n_clusters=20)

return data

def make_estimator(self, params):
representation, algorithm, init = params

max_iter = 30 if representation == 'sparse' else 100

estimator = KMeans(n_clusters=20,
algorithm=algorithm,
init=init,
n_init=1,
max_iter=max_iter,
tol=-1,
random_state=0)

return estimator

def make_scorers(self):
self.train_scorer = (
lambda _, __: neg_mean_inertia(self.X,
self.estimator.predict(self.X),
self.estimator.cluster_centers_))
self.test_scorer = (
lambda _, __: neg_mean_inertia(self.X_val,
self.estimator.predict(self.X_val),
self.estimator.cluster_centers_))


class MiniBatchKMeansBenchmark(Predictor, Transformer, Estimator, Benchmark):
"""
Benchmarks for MiniBatchKMeans.
"""

param_names = ['representation', 'init']
params = (['dense', 'sparse'], ['random', 'k-means++'])

def setup_cache(self):
super().setup_cache()

def make_data(self, params):
representation, init = params

if representation == 'sparse':
data = _20newsgroups_highdim_dataset()
else:
data = _blobs_dataset(n_clusters=20)

return data

def make_estimator(self, params):
representation, init = params

max_iter = 5 if representation == 'sparse' else 2

estimator = MiniBatchKMeans(n_clusters=20,
init=init,
n_init=1,
max_iter=max_iter,
batch_size=1000,
max_no_improvement=None,
compute_labels=False,
random_state=0)

return estimator

def make_scorers(self):
self.train_scorer = (
lambda _, __: neg_mean_inertia(self.X,
self.estimator.predict(self.X),
self.estimator.cluster_centers_))
self.test_scorer = (
lambda _, __: neg_mean_inertia(self.X_val,
self.estimator.predict(self.X_val),
self.estimator.cluster_centers_))
Loading
0