随机搜索给出参数错误? Scikit学习

时间:2018-11-20 10:12:01

标签: python scikit-learn

当我尝试在“随机森林”分类器上运行“随机搜索”时,始终出现错误,如下所示。这是我的代码:

from sklearn.grid_search import RandomizedSearchCV

random_grid = {'criterion':['gini','entropy'],
                'n_estimators':[10, 100, 500, 750, 1000, 120],
                 'max_features':['auto', None,'sqrt','log'],
                 'max_depth':[None, 50, 75, 100],
                 'min_samples_split':[2,4,6,8,10],
                 'min_samples_leaf':[1,2,3]}

random_search = RandomizedSearchCV(estimator = classifier, param_dist = random_grid, cv=10, scoring='accuracy', n_iter=10)
random_search.fit(X_train, y_train)
random_search.best_score_              
random_search.best_params_
random_search.grid_scores_

错误:

 File "<ipython-input-19-e1cdc27aa55f>", line 12, in <module>
    random_search = RandomizedSearchCV(estimator = classifier, param_dist = param_dist, cv=10, scoring='accuracy', n_iter=10)

TypeError: __init__() got an unexpected keyword argument 'param_dist'  

如何解决此问题,我看到它是参数变量,但我不知道如何为随机搜索指定它

1 个答案:

答案 0 :(得分:1)

您使用了错误的参数。 param_dist 应该是 param_distributions 。参见:https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html

random_search = RandomizedSearchCV(estimator = classifier, param_distributions = random_grid, cv=10, scoring='accuracy', n_iter=10)