【发布时间】:2018-10-21 11:54:30
【问题描述】:
我在 Python 中阅读了以下有关 Pipelines 和 GridSearchCV 的示例: http://www.davidsbatista.net/blog/2017/04/01/document_classification/
逻辑回归:
pipeline = Pipeline([
('tfidf', TfidfVectorizer(stop_words=stop_words)),
('clf', OneVsRestClassifier(LogisticRegression(solver='sag')),
])
parameters = {
'tfidf__max_df': (0.25, 0.5, 0.75),
'tfidf__ngram_range': [(1, 1), (1, 2), (1, 3)],
"clf__estimator__C": [0.01, 0.1, 1],
"clf__estimator__class_weight": ['balanced', None],
}
支持向量机:
pipeline = Pipeline([
('tfidf', TfidfVectorizer(stop_words=stop_words)),
('clf', OneVsRestClassifier(LinearSVC()),
])
parameters = {
'tfidf__max_df': (0.25, 0.5, 0.75),
'tfidf__ngram_range': [(1, 1), (1, 2), (1, 3)],
"clf__estimator__C": [0.01, 0.1, 1],
"clf__estimator__class_weight": ['balanced', None],
}
有没有一种方法可以将逻辑回归和 SVM 组合到 one 管道中?比如说,我有一个 TfidfVectorizer,并且喜欢针对多个分类器进行测试,然后每个分类器都输出最佳模型/参数。
【问题讨论】:
-
你在做什么here in this question是正确的。这就是我在上面的答案中所做的。
标签: python scikit-learn pipeline grid-search