您必须先对数据进行拟合,才能获得最佳的参数组合。
from sklearn.grid_search import GridSearchCVfrom sklearn.datasets import make_classificationfrom sklearn.ensemble import RandomForestClassifier# Build a classification task using 3 informative featuresX, y = make_classification(n_samples=1000, n_features=10, n_informative=3, n_redundant=0, n_repeated=0, n_classes=2, random_state=0, shuffle=False)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)CV_rfc.fit(X, y)print CV_rfc.best_params_


