我正在运行GridSearch CV来优化scikit中分类器的参数。完成后,我想知道哪些参数被选为最佳。但每次这样做时,我都会收到一个“AttributeError: 'RandomForestClassifier' object has no attribute 'best_estimator_'”错误,无法确定原因,因为它似乎是文档上合法的属性。
from sklearn.grid_search import GridSearchCV
X = data[usable_columns]
y = data[target]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
rfc = RandomForestClassifier(n_jobs=-1,max_features= 'sqrt' ,n_estimators=50, oob_score = True)
param_grid = {
'n_estimators': [200, 700],
'max_features': ['auto', 'sqrt', 'log2']
}
CV_rfc = GridSearchCV(estimator=rfc, param_grid=param_grid, cv= 5)
print '\n',CV_rfc.best_estimator_
产量:
`AttributeError: 'GridSearchCV' object has no attribute 'best_estimator_'