所以我正在做RandomForest和GridsearchCV一些參數的事情。這是我的代碼。與RandomForest GridsearchCV
#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異常:無效參數max_features的估計GridSearchCV請與estimator.get_params().keys()
可用參數列表。」
我按照錯誤給出的建議,print(clf.get_params()。keys())的輸出如下。但是,即使我將這些標題複製並粘貼到我的參數字典中,我仍然遇到錯誤。我已經在堆棧溢出問題上進行了尋找,大多數人都使用非常類似的參數字典來挖掘。任何人都有如何解決這個問題的想法?再次感謝!
dict_keys([ 'pre_dispatch', 'CV', 'estimator__max_features', 'param_grid', '改裝', 'estimator__min_impurity_split', 'n_jobs', 'estimator__random_state', 'error_score', '冗長', 'estimator__min_samples_split' ,'estimator__n_jobs','fit_params','estimator__min_weight_fraction_leaf','評分','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'])
就是這樣!謝謝,我也是通過再讀一遍纔得到它的! – Jake3991