python并行调参——scikit-learn grid_search
上篇 应用scikit-learn做文本分类 中以20newsgroups为例讲了如何用三种方法提取训练集=测试集的文本feature,但是
vectorizer取多少个word呢?
预处理时候要过滤掉tf>max_df的words,max_df设多少呢?
tfidftransformer只用tf还是加idf呢?
classifier分类时迭代几次?学习率怎么设?
……
“循环一个个试过来啊”……啊好吧,matlab里就是这么做的……
好在scikit-learn中提供了pipeline(for estimator connection) & grid_search(searching best parameters)进行并行调参。
官网上pipeline 解释如下:
Pipeline can be used to chain multiple estimators into one. This is useful as there is often a fixed sequence of steps in processing the data, for example feature selection, normalization and classification. Pipeline serves two purposes here:
Convenience : You only have to call fit and predict once on your data to fit a whole sequence of estimators.
Joint parameter selection : You can grid search