grid search 超参数寻优
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了grid search 超参数寻优相关的知识,希望对你有一定的参考价值。
http://scikit-learn.org/stable/modules/grid_search.html
1. 超参数寻优方法 gridsearchCV 和 RandomizedSearchCV
2. 参数寻优的技巧进阶
2.1. Specifying an objective metric
By default, parameter search uses the score
function of the estimator to evaluate a parameter setting. These are thesklearn.metrics.accuracy_score
for classification and sklearn.metrics.r2_score
for regression.
2.2 Specifying multiple metrics for evaluation
Multimetric scoring can either be specified as a list of strings of predefined scores names or a dict mapping the scorer name to the scorer function and/or the predefined scorer name(s).
http://scikit-learn.org/stable/modules/model_evaluation.html#multimetric-scoring
2.3 Composite estimators and parameter spaces 。pipeline 方法
http://scikit-learn.org/stable/modules/pipeline.html#pipeline
>>> from sklearn.pipeline import Pipeline
>>> from sklearn.svm import SVC
>>> from sklearn.decomposition import PCA
>>> estimators = [(‘reduce_dim‘, PCA()), (‘clf‘, SVC())]
>>> pipe = Pipeline(estimators)
>>> pipe # check pipe
Pipeline(memory=None,
steps=[(‘reduce_dim‘, PCA(copy=True,...)),
(‘clf‘, SVC(C=1.0,...))])
>>> from sklearn.pipeline import make_pipeline
>>> from sklearn.naive_bayes import MultinomialNB
>>> from sklearn.preprocessing import Binarizer
>>> make_pipeline(Binarizer(), MultinomialNB())
Pipeline(memory=None,
steps=[(‘binarizer‘, Binarizer(copy=True, threshold=0.0)),
(‘multinomialnb‘, MultinomialNB(alpha=1.0,
class_prior=None,
fit_prior=True))])
>>> pipe.set_params(clf__C=10) # 给clf 设定参数
>>> from sklearn.model_selection import GridSearchCV
>>> param_grid = dict(reduce_dim__n_components=[2, 5, 10],
... clf__C=[0.1, 10, 100])
>>> grid_search = GridSearchCV(pipe, param_grid=param_grid)
以上是关于grid search 超参数寻优的主要内容,如果未能解决你的问题,请参考以下文章
python中算法(sklearn)的最优超参数寻优:skopt贝叶斯搜索
R语言caret包构建xgboost模型实战:特征工程(连续数据离散化因子化无用特征删除)配置模型参数(随机超参数寻优10折交叉验证)并训练模型
Keras训练神经网络进行分类并使用GridSearchCV进行参数寻优