Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在网格搜索中设置交叉验证参数_Python_Numpy_Random Forest_Grid Search - Fatal编程技术网

Python 在网格搜索中设置交叉验证参数

Python 在网格搜索中设置交叉验证参数,python,numpy,random-forest,grid-search,Python,Numpy,Random Forest,Grid Search,我试图在GridSearch中设置一个RandomForestClassification rfc_model = RandomForestClassifier(n_estimators = 5, max_depth = 3 ) gs = grid_search.GridSearchCV(estimator = rfc_model, param_grid = {'n_estimators': [i for i in range(1,52

我试图在GridSearch中设置一个RandomForestClassification

rfc_model = RandomForestClassifier(n_estimators = 5, max_depth = 3 )

gs = grid_search.GridSearchCV(estimator = rfc_model,
                             param_grid = {'n_estimators': [i for i in range(1,52,10)],
                                          "max_depth": [3, 5],
                                          "bootstrap": [True, False],
                                          "criterion": ["gini"]},
                             cv = cross_val_score(rfc_model,X, y, scoring='roc_auc'))

gs.fit(X, y)
gs.grid_scores_
print gs.best_estimator
print gs.best_score_
我得到了错误

TypeError:“numpy.float64”对象不可编辑


显然,我正在学习,所以欢迎发表任何评论。

好的,我发现了问题,我使用了错误的方法。可以称之为方法吗?对于交叉验证,请参见解决方案下方:

gs = grid_search.GridSearchCV(estimator = model,
                             param_grid = {'n_estimators': [i for i in range(1,52,10)],
                                          "max_depth": [3, 5],
                                          "bootstrap": [True, False],
                                          "criterion": ["gini"]},
                             cv = cross_validation.KFold(n=len(X), n_folds=10), scoring='roc_auc')
这可能对你有帮助