从 Scikit (Python) 中的管道检索中间特征

2024-02-13

我使用的管道与给定的管道非常相似在这个例子中 http://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html#building-a-pipeline :

>>> text_clf = Pipeline([('vect', CountVectorizer()),
...                      ('tfidf', TfidfTransformer()),
...                      ('clf', MultinomialNB()),
... ])

我用过的GridSearchCV找到参数网格上的最佳估计器。

但是,我想获取我的训练集的列名称get_feature_names()方法来自CountVectorizer()。这是否可以在不实施的情况下实现CountVectorizer()管道外?


使用get_params()函数中,您可以访问管道的各个部分及其各自的内部参数。下面是一个访问的例子'vect'

text_clf = Pipeline([('vect', CountVectorizer()),
                     ('tfidf', TfidfTransformer()),
                     ('clf', MultinomialNB())]
print text_clf.get_params()['vect']

产量(对我来说)

CountVectorizer(analyzer=u'word', binary=False, decode_error=u'strict',
    dtype=<type 'numpy.int64'>, encoding=u'utf-8', input=u'content',
    lowercase=True, max_df=1.0, max_features=None, min_df=1,
    ngram_range=(1, 1), preprocessor=None, stop_words=None,
    strip_accents=None, token_pattern=u'(?u)\\b\\w\\w+\\b',
    tokenizer=None, vocabulary=None)

我还没有将管道安装到本示例中的任何数据,因此调用get_feature_names()此时会返回错误。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 Scikit (Python) 中的管道检索中间特征 的相关文章

随机推荐