Skip to content

Instantly share code, notes, and snippets.

Last active Jul 16, 2019
What would you like to do?
Benchmark of GaussianProcessClassifier for
import time
import numpy as np
from sklearn.datasets import load_iris
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import RBF
def main():
# based on example of
X, y = load_iris(return_X_y=True)
kernel = 1.0 * RBF(1.0)
clf = GaussianProcessClassifier(kernel=kernel, random_state=0)
times = []
for i in range(10):
start = time.time(), y)
elapsed = time.time() - start
print(f"elapsed: {elapsed:.3f}s")
print("score", clf.score(X, y))
print("mean/std", np.array(times).mean(), np.array(times).std())
proba = clf.predict_proba(X[:2, :])"proba", proba)
orig_proba = np.load("proba.npy")
np.testing.assert_allclose(orig_proba, proba)
if __name__ == '__main__':
Copy link

c-bata commented Jul 16, 2019


$ python examples/ 
elapsed: 0.793s
elapsed: 0.702s
elapsed: 0.809s
elapsed: 0.727s
elapsed: 0.798s
elapsed: 0.750s
elapsed: 1.620s
elapsed: 0.979s
elapsed: 0.768s
elapsed: 0.764s
score 0.9866666666666667
mean/std 0.8710338830947876 0.2594975969201766


$ python examples/ 
elapsed: 0.589s
elapsed: 0.653s
elapsed: 0.652s
elapsed: 0.647s
elapsed: 0.673s
elapsed: 0.680s
elapsed: 0.690s
elapsed: 0.637s
elapsed: 0.651s
elapsed: 0.646s
score 0.9866666666666667
mean/std 0.6519202470779419 0.0264506890882865

almost 25.2% faster in this benchmark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment