【机器学习-参数篇】GridSearch 调节超参数

GridSearch ?

参考链接
GridSearchCV存在的意义就是自动调参,只要把参数输进去,就能给出最优化的结果和参数。
but这个方法适合于小数据集,一旦数据的量级上去了,很难得出结果。
数据量比较大的时候可以使用一个快速调优的方法——坐标下降。它其实是一种贪心算法:拿当前对模型影响最大的参数调优,直到最优化;再拿下一个影响最大的参数调优,如此下去,直到所有的参数调整完毕。这个方法的缺点就是可能会调到局部最优而不是全局最优,但是省时间省力,巨大的优势面前,还是试一试吧,后续可以再拿bagging再优化。
回到sklearn里面的GridSearchCV,GridSearchCV用于系统地遍历多种参数组合,通过交叉验证确定最佳效果参数。

参数解读

1、estimator: 分类器

如: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,则使用estimator的误差估计函数。

其中参数如下:

ScoringFunctionComment
Classification
accuracymetrics.accuracy_score
balanced_accuracymetrics.balanced_accuracy_scorefor binary targets
average_precisionmetrics.average_precision_score
brier_score_lossmetrics.brier_score_loss
f1metrics.f1_scorefor binary targets
f1_micrometrics.f1_scoremicro-averaged
f1_macrometrics.f1_scoremacro-averaged
f1_weightedmetrics.f1_scoreweighted average
f1_samplesmetrics.f1_scoreby multilabel sample
neg_log_lossmetrics.log_lossrequires predict_proba support
‘precision’ etc.metrics.precision_scoresuffixes apply as with f1
‘recall’ etc.metrics.recall_scoresuffixes apply as with f1
roc_aucmetrics.roc_auc_score
Clustering
adjusted_mutual_info_scoremetrics.adjusted_mutual_info_score
adjusted_rand_scoremetrics.adjusted_rand_score
completeness_scoremetrics.completeness_score
fowlkes_mallows_scoremetrics.fowlkes_mallows_score
homogeneity_scoremetrics.homogeneity_score
mutual_info_scoremetrics.mutual_info_score
normalized_mutual_info_scoremetrics.normalized_mutual_info_score
v_measure_scoremetrics.v_measure_score
Regression
explained_variancemetrics.explained_variance_score
neg_mean_absolute_errormetrics.mean_absolute_error
neg_mean_squared_errormetrics.mean_squared_error
neg_mean_squared_log_errormetrics.mean_squared_log_error
neg_median_absolute_errormetrics.median_absolute_error
r2metrics.r2_score

4、CV:交叉验证参数,默认为None,使用3折交叉验证。指定fold数量,也可以是yield训练\测试数据的生成器。

5、n_jobs:并行数,int:个数,-1:跟CPU核数一直,默认值为1。

输出结果

grid.fit():运行网格搜索
grid_scores_:给出不同参数情况下的评价结果
best_params_:描述了已取得最佳结果的参数的组合
best_score_:成员提供优化过程期间观察到的最好的评分

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值