sklearn的GridSearchCV


class sklearn.model_selection.GridSearchCV
(estimator, param_grid, scoring=None, 
fit_params=None, n_jobs=1, iid=True, refit=True, 
cv=None, verbose=0, pre_dispatch=‘2*n_jobs’, error_score=’raise’,
return_train_score=’warn’)

(1)estimator
选择使用的分类器,并且传入除需要确定最佳的参数之外的其他参数。每一个分类器都需要一个scoring参数,或者score方法:

estimator=RandomForestClassifier(min_samples_split=100,min_samples_leaf=20,
max_depth=8,max_features='sqrt',random_state=10)

(2)param_grid
需要最优化的参数的取值,值为字典或者列表,例如:

param_grid =param_test1,param_test1 = {'n_estimators':range(10,71,10)}。

(3)scoring=None
模型评价标准,默认None,这时需要使用score函数;或者如scoring='roc_auc',根据所选模型不同,评价准则不同。字符串(函数名),或是可调用对象,需要其函数签名形如:scorer(estimator, X, y);如果是None,则使用estimator的误差估计函数。具体值的选取看本篇第三节内容。

sklearn的GridSearchCV_第1张图片
image.png
gsearch = GridSearchCV(model,param_grid,scoring = 'neg_log_loss',n_jobs = -1,cv = kflod)
grid_result =gsearch.fit(X,y)
print(grid_result.best_params_, grid_result.best_score_)

#grid_scores_:给出不同参数情况下的评价结果。best_params_:描述了已取得最佳结果的参数的组合
#best_score_:成员提供优化过程期间观察到的最好的评分

你可能感兴趣的:(sklearn的GridSearchCV)