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)