简体   繁体   English

来自 SCIKIT 学习用户指南的 GridSearch 示例尝试给出错误

[英]GridSearch example from SCIKIT learn user guide tried giving error

Was trying to run the same code as per the SCIKIT user guide of Grid search but giving error.Quite surprised.试图按照网格搜索的 SCIKIT 用户指南运行相同的代码,但出现错误。非常惊讶。

from sklearn.model_selection import GridSearchCV
from sklearn.calibration import CalibratedClassifierCV
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_moons
from sklearn.model_selection import cross_val_score
from sklearn.datasets import load_iris
X,y=make_moons()
calibrated_forest=CalibratedClassifierCV(base_estimator=RandomForestClassifier(n_estimators=10))
paramgrid={'base_estimator_max_depth':[2,4,6,8]}
search=GridSearchCV(calibrated_forest,paramgrid,cv=5)
search.fit(X,y)

Error message as below:错误信息如下:

ValueError: Invalid parameter base_estimator_max_depth for estimator CalibratedClassifierCV(base_estimator=RandomForestClassifier(n_estimators=10)). Check the list of available parameters with `estimator.get_params().keys()`.

I tried with Iris data set which also gave the same error as above.我尝试使用 Iris 数据集,它也给出了与上述相同的错误。

Then i used the make_moon dataset X,y and run the Random classifier as below.然后我使用 make_moon 数据集 X,y 并运行随机分类器,如下所示。

clf = RandomForestClassifier(n_estimators=10, max_depth=2)
cross_val_score(clf, X, y, cv=5)

Got the output as below.得到如下输出。

array([0.8 , 0.8 , 0.9 , 0.95, 0.95])

Looking strange and not sure what is happening and where iam wrong.看起来很奇怪,不确定发生了什么以及我错在哪里。 Request help please.请请求帮助。

Note the double score __ between base_estimator and a param:请注意base_estimator和参数之间的双分__

from sklearn.model_selection import GridSearchCV
from sklearn.calibration import CalibratedClassifierCV
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_moons
from sklearn.model_selection import cross_val_score
from sklearn.datasets import load_iris
X,y=make_moons()
calibrated_forest=CalibratedClassifierCV(base_estimator=RandomForestClassifier(n_estimators=10))
paramgrid={'base_estimator__max_depth':[2,4,6,8]}
search=GridSearchCV(calibrated_forest,paramgrid,cv=5)
search.fit(X,y)
GridSearchCV(cv=5,
             estimator=CalibratedClassifierCV(base_estimator=RandomForestClassifier(n_estimators=10)),
             param_grid={'base_estimator__max_depth': [2, 4, 6, 8]})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM