管道:多个分类器?

2024-05-15 23:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python中阅读了以下关于管道和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],
}

Logistic回归和支持向量机是否可以合并成一个管道?比方说,我有一个TfidfVectorizer,并且喜欢测试多个分类器,每个分类器都输出最好的模型/参数。


Tags: df管道pipelinerangemaxtfidfparametersstop