Skip to content

Instantly share code, notes, and snippets.

@pprett pprett/bench_tree.py
Created Jul 11, 2012

Embed
What would you like to do?
Simple and stupid benchmark for sklearn DecisionTreeRegressor
import numpy as np
from sklearn import datasets
from sklearn.ensemble import gradient_boosting
from sklearn.ensemble import RandomForestClassifier,RandomForestRegressor
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
X, y = datasets.make_hastie_10_2(n_samples=12000, random_state=1)
X = X.astype(np.float32)
print "%timeit clf.fit(X, y)"
boston = datasets.load_boston()
X, y = boston.data, boston.target
clf = DecisionTreeRegressor(max_depth=20)
%timeit clf.fit(X, y)
%timeit clf.predict(X)
clf = DecisionTreeRegressor(max_depth=1)
%timeit clf.fit(X, y)
%timeit clf.predict(X)
clf = RandomForestRegressor()
%timeit clf.fit(X, y)
%timeit clf.predict(X)
clf = gradient_boosting.GradientBoostingRegressor(n_estimators=250,
max_depth=1,
learn_rate=1.0)
%timeit clf.fit(X, y)
%timeit clf.predict(X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.