码迷,mamicode.com
首页 > 其他好文 > 详细

grid search 超参数寻优

时间:2017-09-05 13:59:12      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:modules   hold   selection   技巧   repr   参数   select   pip   eva   

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 超参数寻优

标签:modules   hold   selection   技巧   repr   参数   select   pip   eva   

原文地址:http://www.cnblogs.com/xinping-study/p/7478252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!