2017-07-30 4 views
0

私はRandomForestとGridsearchCVでいくつかのパラメータをしています。ここに私のコードです。GridsearchCV with RandomForest

#Import 'GridSearchCV' and 'make_scorer' 
from sklearn.model_selection import GridSearchCV 
from sklearn.metrics import make_scorer 

Create the parameters list you wish to tune 
parameters = {'n_estimators':[5,10,15]} 

#Initialize the classifier 
clf = GridSearchCV(RandomForestClassifier(), parameters) 

#Make an f1 scoring function using 'make_scorer' 
f1_scorer = make_scorer(f1_scorer) 

#Perform grid search on the classifier using the f1_scorer as the scoring method 
grid_obj = GridSearchCV(clf, param_grid=parameters, scoring=f1_scorer,cv=5) 

print(clf.get_params().keys()) 

#Fit the grid search object to the training data and find the optimal parameters 
grid_obj = grid_obj.fit(X_train_100,y_train_100) 

だから、問題は次のエラーです:「とValueError:推定器GridSearchCVの無効なパラメータmax_featuresはestimator.get_params().keys()で使用可能なパラメータのリストを確認してください。」

私はエラーによって与えられた助言に従い、print(clf.get_params()。keys())の出力は以下の通りです。しかし、これらのタイトルをコピーしてパラメータ辞書に貼り付けるときでも、私はまだエラーが発生します。私はスタックオーバーフローの周りを狩り、ほとんどの人は私のために本当に似たようなパラメータ辞書を使用しています。誰もがこの問題を解消する方法を知っていますか?再度、感謝します!

dict_keys([ 'pre_dispatch'、 'C​​V'、 'estimator__max_features'、 'param_grid'、 '修理'、 'estimator__min_impurity_split'、 'n_jobs'、 'estimator__random_state'、 'error_score'、 '詳細'、 'estimator__min_samples_split' 'estimator__nobjobs'、 'fit_params'、 'estimator__min_weight_fraction_leaf'、 'scoring'、 'estimator__warm_start'、 'estimator__criterion'、 'estimator__verbose'、 'estimator__bootstrap'、 'estimator__class_weight'、 'estimator__oob_score'、 'iid'、 'estimator'、 ' estimator__max_depth」、 'estimator__max_leaf_nodes'、 'estimator__min_samples_leaf'、 'estimator__n_estimators'、 'return_train_score'])

答えて

2

私は問題は二行であると思う:

clf = GridSearchCV(RandomForestClassifier(), parameters) 
grid_obj = GridSearchCV(clf, param_grid=parameters, scoring=f1_scorer,cv=5) 

これは、本質的に似た構造を持つオブジェクトを作成してやっている:おそらくあなたが望むよりもGridSearchCV 1以上をある

grid_obj = GridSearchCV(GridSearchCV(RandomForestClassifier())) 

+0

それでした!ありがとう、私はそれをまた読んでもらえました! – Jake3991

関連する問題