參考:http://scikit-learn.org/stable/modules/grid_search.html

GridSearchCV通过(蛮力)搜索參数空间(參数的全部可能组合)。寻找最好的 Cross-validation:
evaluating estimator performance
 score相应的超參数(翻译文章參考:http://blog.csdn.net/mmc2015/article/details/47099275)。比如Support
Vector Classifier的 Ckernel and gamma ,Lasso的alpha。etc。

A search consists of:

  • an estimator (regressor or classifier such as sklearn.svm.SVC());
  • a parameter space;
  • a method for searching or sampling candidates;
  • a cross-validation scheme
  • score
    function
    .

RandomizedSearchCV 通过一定的分布sample候选參数。而不是搜索全部參数组合。

本节我们介绍 GridSearchCVRandomizedSearchCV 、以及parameter
search的小Tips,最后介绍蛮力搜索的alternatives

1、Exhaustive
Grid Search

GridSearchCV的參数param_grid定义搜索网格。

两个样例说明一切:

2、Randomized
Parameter Optimization

RandomizedSearchCV 通过在參数可能的取值的某个分布中sample一组參数。优点是:能够设定独立于參数(及全部取值)详细数量的一个搜索次数;加入无效的參数也不会减少效率。

搜索的次数通过 n_iter 设定,对于每个參数,假设是连续的取值。则通过一定的分布sample,假设是离散的取值,则通过uniform分布sample,比如:

[{'C': scipy.stats.expon(scale=100), 'gamma': scipy.stats.expon(scale=.1),
'kernel': ['rbf'], 'class_weight':['auto', None]}]

scipy.stats module提供了非常多用来sample參数的distributions,如expongammauniform or randint.

对于连续的參数,如 C ,一定要选择连续的分布来sample,而且适当增大 n_iter 通常会搜索到更好的參数组合。

给个样例:

3、Tips
for parameter search(这几个建议很靠谱。。。

1)详细化目标函数

參数搜索默认使用score function(
即,分类用sklearn.metrics.accuracy_score 回归用sklearn.metrics.r2_score )来衡量參数的好坏对于有些应用(比方分类unbalance,score不是非常好的标准),通过详细化GridSearchCVRandomizedSearchCV 的scoring parameter。See The
scoring parameter: defining model evaluation rules
 for more details.

2)综合estimators和parameter sapces(同一时候考虑预測器和參数空间)

Pipeline:
chaining estimators
 describes building composite estimators whose parameter space can be searched with these tools.

3)模型选择:先训练、再评估

用训练集选择模型。用測试集验证模型(using
the cross_validation.train_test_split utility
function.
)(it is recommended to split the data into a development set (to be
fed to the GridSearchCV instance)
and an evaluation set to compute performance metrics.)

4)并行搜索

n_jobs=-1.
自己主动使用全部核。

5)robustness to failure(增强搜索错误的鲁棒性)

有些參数组合对于某些folds
of the data会failure,进而导致整个search failure,虽然其它的參数组合没有问题。

设定 error_score=0 (or =np.NaN)
能够使search过程忽略这种failure,只抛出一个warning,并将这种search结果设为0 (or =np.NaN)
,可以提高搜索遇到错误时的鲁棒性!

4、Alternatives
to brute force parameter search(没太看懂,还是不翻译了)

3.2.4.1. Model specific cross-validation

Some models can fit data for a range of value of some parameter almost as efficiently as fitting the estimator for a single value of the parameter. This feature can be leveraged to perform
a more efficient cross-validation used for model selection of this parameter.

The most common parameter amenable to this strategy is the parameter encoding the strength of the regularizer. In this case we say that we compute theregularization path of
the estimator.

Here is the list of such models:

linear_model.ElasticNetCV([l1_ratio, eps, ...]) Elastic Net model with iterative fitting along a regularization path
linear_model.LarsCV([fit_intercept, ...]) Cross-validated Least Angle Regression model
linear_model.LassoCV([eps, n_alphas, ...]) Lasso linear model with iterative fitting along a regularization path
linear_model.LassoLarsCV([fit_intercept, ...]) Cross-validated Lasso, using the LARS algorithm
linear_model.LogisticRegressionCV([Cs, ...]) Logistic Regression CV (aka logit, MaxEnt) classifier.
linear_model.MultiTaskElasticNetCV([...]) Multi-task L1/L2 ElasticNet with built-in cross-validation.
linear_model.MultiTaskLassoCV([eps, ...]) Multi-task L1/L2 Lasso with built-in cross-validation.
linear_model.OrthogonalMatchingPursuitCV([...]) Cross-validated Orthogonal Matching Pursuit model (OMP)
linear_model.RidgeCV([alphas, ...]) Ridge regression with built-in cross-validation.
linear_model.RidgeClassifierCV([alphas, ...]) Ridge classifier with built-in cross-validation.

3.2.4.2. Information Criterion

Some models can offer an information-theoretic closed-form formula of the optimal estimate of the regularization parameter by computing a single regularization path (instead of several when
using cross-validation).

Here is the list of models benefitting from the Aikike Information Criterion (AIC) or the Bayesian Information Criterion (BIC) for automated model selection:

linear_model.LassoLarsIC([criterion, ...]) Lasso model fit with Lars using BIC or AIC for model selection

3.2.4.3. Out of Bag Estimates

When using ensemble methods base upon bagging, i.e. generating new training sets using sampling with replacement, part of the training set remains unused. For each classifier in the ensemble,
a different part of the training set is left out.

This left out portion can be used to estimate the generalization error without having to rely on a separate validation set. This estimate comes “for free” as no additional data is needed and
can be used for model selection.

This is currently implemented in the following classes:

ensemble.RandomForestClassifier([...]) A random forest classifier.
ensemble.RandomForestRegressor([...]) A random forest regressor.
ensemble.ExtraTreesClassifier([...]) An extra-trees classifier.
ensemble.ExtraTreesRegressor([n_estimators, ...]) An extra-trees regressor.
ensemble.GradientBoostingClassifier([loss, ...]) Gradient Boosting for classification.
ensemble.GradientBoostingRegressor([loss, ...]) Gradient Boosting for regression.

scikit-learn:3.2. Grid Search: Searching for estimator parameters的更多相关文章

  1. 3.2. Grid Search: Searching for estimator parameters

    3.2. Grid Search: Searching for estimator parameters Parameters that are not directly learnt within ...

  2. How to Grid Search Hyperparameters for Deep Learning Models in Python With Keras

    Hyperparameter optimization is a big part of deep learning. The reason is that neural networks are n ...

  3. scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类 (python代码)

    scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类数据集 fetch_20newsgroups #-*- coding: UTF-8 -*- import ...

  4. (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探

    目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...

  5. Grid search in the tidyverse

    @drsimonj here to share a tidyverse method of grid search for optimizing a model's hyperparameters. ...

  6. (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探

    一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...

  7. Extjs4.2 Grid搜索Ext.ux.grid.feature.Searching的使用

    背景 Extjs4.2 默认提供的Search搜索,功能还是非常强大的,只是对于国内的用户来说,还是不习惯在每列里面单击好几下再筛选,于是相当当初2.2里面的搜索,更加的实用点,于是在4.2里面实现. ...

  8. Ext.ux.grid.feature.Searching 解析查询参数,动态产生linq lambda表达式

    上篇文章中http://www.cnblogs.com/qidian10/p/3209439.html我们介绍了如何使用Grid的查询组建,而且将查询的参数传递到了后台. 那么我们后台如何介绍参数,并 ...

  9. Grid Search学习

    转自:https://www.cnblogs.com/ysugyl/p/8711205.html Grid Search:一种调参手段:穷举搜索:在所有候选的参数选择中,通过循环遍历,尝试每一种可能性 ...

随机推荐

  1. js效果之导航中英文转换

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. How Javascript works (Javascript工作原理) (四) 事件循环及异步编程的出现和 5 种更好的 async/await 编程方式

    个人总结: 1.讲解了JS引擎,webAPI与event loop合作的机制. 2.setTimeout是把事件推送给Web API去处理,当时间到了之后才把setTimeout中的事件推入调用栈. ...

  3. JavaScript函数练习

    1. 判断一个数是否是素数 function isSushu (n) { n = n || 0; var isSu = true; for (var i = 2; i <= Math.sqrt( ...

  4. vuex 基本入门和使用(三)-关于 mutation

    vuex 基本入门和使用(三)-关于 mutation vuex 版本为^2.3.1,按照我自己的理解来整理vuex. 关于 mutation 这里应该很好理解. 更改 Vuex 的 store 中的 ...

  5. python基础7(函数 Ⅱ)

    1.python代码运行遇到函数时 从python解释器开始执行之后,就在内存中开辟了一个空间 每当遇到一个变量的时候,就把变量名和值之间的对应关系记录下来. 但是当遇到函数定义的时候解释器只是象征性 ...

  6. 【Oracle】Exadata虚拟机配置(一)

    Exadata是Oracle软硬结合的一体机.通过自己的机子不可能全然模拟出来,这里搭建的虚拟机仅仅是一个简单的.能够供我们学习Exadata的环境. 最简单能够模拟的Exadata虚拟机须要两个节点 ...

  7. Scala学习笔记及与Java不同之处总结-从Java开发者角度

    Scala与Java具有很多相似之处,但又有很多不同.这里主要从一个Java开发者的角度,总结在使用Scala的过程中所面临的一些思维转变. 这里仅仅是总结了部分两种语言在开发过程中的不同,以后会陆续 ...

  8. spark 卡在spark context,运行出现spark Exception encountered while connecting to the server : javax.security.sasl.SaslException

    原因: 使用root用户运行spark代码 解决方法:使用非管理员账户运行spark即可 [userone@localhost bin]$ ./add-user.sh What type of use ...

  9. MinGW - 安装和配置 / MinGW - Howto Install And Configure

    MinGW在线安装程序下载地址:http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get- ...

  10. border:none与border:0的区别

    border:none与border:0的区别体现为两点:一是理论上的性能差异,二是浏览器兼容性的差异. 性能差异: [border:0;]把border设为“0”像素效果等于border-width ...