2017-05-08 73 views
0

我想設置一個GridSearch設置交叉驗證參數網格搜索

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' object is not iterable

顯然我學習裏面RandomForestClassification,所以任何意見,歡迎。

+0

http://stackoverflow.com/a/16865814/7714663這可能會幫助你 –

回答

0

好吧,我發現這個問題,我用錯了方法(它是正常的調用它的方法?)的交叉驗證,該解決方案如下:

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')