Scikit学习zip参数#1必须支持迭代



我有以下管道在语料库上执行机器学习。它首先提取文本,使用TfidfVectorizer提取n-gram,然后选择最佳特征。如果没有功能选择步骤,管道工作正常。然而,有了它,我得到了

 Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 90, in __init__
    names, estimators = zip(*steps)
TypeError: zip argument #1 must support iteration

在CCD_ 2处。

pipeline = Pipeline([
    # Use FeatureUnion to combine the features
    ('features', FeatureUnion(
        transformer_list=[
            # N-GRAMS
            ('ngrams', Pipeline([
                ('extractor', TextExtractor(normalized=True)), # returns a list of strings
                ('vectorizer', TfidfVectorizer(analyzer='word', strip_accents='ascii', use_idf=True, norm="l2", min_df=3, max_df=0.90)),
                ('feature_selection', SelectPercentile(score_func=chi2, percentile=70)),
            ])),
        ],,
    )),
    ('clf', Pipeline([
        SGDClassifier(n_jobs=-1, verbose=0)
    ])),
])

看起来您错过了Pipeline 中的一个标签

('clf', Pipeline([
    SGDClassifier(n_jobs=-1, verbose=0)
])),

应该是

('clf', Pipeline([
    ('sgd', SGDClassifier(n_jobs=-1, verbose=0))
])),

相关内容

  • 没有找到相关文章

最新更新