-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
GridSearchCV of sklearn.model_selection is slower than its deprecated predecessor from sklearn.grid_search #9619
Copy link
Copy link
Closed
Description
Description
The GridSearchCV from module sklearn.model_selection operates slower than the "old" one from sklearn.grid_selection, that has been marked as deprecated.
Steps/Code to Reproduce
The below example has been taken from this thread.
Example:
import matplotlib.pyplot as plt
from scipy.stats.distributions import norm
import time
# Draw points from a bimodal distribution in 1D
xgrid = np.linspace(-4.5, 3.5, 1000)
np.random.seed(0)
x = np.concatenate([norm(-1, 1.).rvs(400),
norm(1, 0.3).rvs(100)])
pdfTrue = (0.8 * norm(-1, 1).pdf(xgrid) +
0.2 * norm(1, 0.3).pdf(xgrid))
fig, ax = plt.subplots()
ax.hist(x, 30, fc='gray', histtype='stepfilled', alpha=0.3, normed=True)
ax.set_xlim(-4.5, 3.5)
from sklearn.neighbors import KernelDensity
#####################################################
# HERE SWITCH BETWEEN ONE OF THE GRIDSEARCHCV CLASSES
#from sklearn.grid_search import GridSearchCV
from sklearn.model_selection import GridSearchCV
#####################################################
start = time.time()
grid = GridSearchCV(KernelDensity(),
{'bandwidth': np.linspace(0.1, 1.0, 30)},
cv=20) # 20-fold cross-validation
grid.fit(x[:, None])
kde = grid.best_estimator_
pdf = np.exp(kde.score_samples(xgrid[:, None]))
ax.plot(xgrid, pdf, linewidth=3, alpha=0.5, label='bw=%.2f' % kde.bandwidth)
print time.time()-start, 'seconds'
plt.show()Expected Results
Results are the same, runtime is the same.
Actual Results
Results look the same, but the runtime of the recommended GridSearchCV is 5-6 times slower than the one marked as deprecated.
Versions
Darwin-15.6.0-x86_64-i386-64bit
('Python', '2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]')
('NumPy', '1.14.0.dev0+029863e')
('SciPy', '0.18.1')
('Scikit-Learn', '0.19.0')
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels