Reputation: 10083
I am struggling to understand how the grid_search
class works. I want to find the best max_depth
parameter which I can use with the RandomForestClassifier
. I specified the possible options I wanted the search to run through, and I expected the module to output the "best fitting" max_depth
option.
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn import grid_search
iris= load_iris()
forest_parameters = {'max_depth': [1,2,3,4]}
forest = RandomForestClassifier()
explorer = grid_search.GridSearchCV(forest, forest_parameters)
explorer.fit(iris['data'], iris['target'])
I expected my explorer
grid search module to return with the best max_depth
parameter, given the set of possible options [1,2,3,4]
. Why is the default value of None
still being used? How can I use grid_search
to find "best-fitting" parameters?
Out[13]:
GridSearchCV(cv=None, error_score='raise',
estimator=RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
---> max_depth=None, max_features='auto', max_leaf_nodes=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
oob_score=False, random_state=None, verbose=0,
warm_start=False),
fit_params={}, iid=True, loss_func=None, n_jobs=1,
param_grid={'max_depth': [1, 2, 3, 4]}, pre_dispatch='2*n_jobs',
refit=True, score_func=None, scoring=None, verbose=0)
Upvotes: 1
Views: 863
Reputation: 8270
Those are only the parameters the grid search was invoked with. To identify to the best parameters use explorer.best_params_
, or you could find the estimator using explorer.best_estimator_
, provided refit
is enabled.
Upvotes: 2