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

Tan*_*guy 7 python pipeline scikit-learn

我使用的管道非常类似于此示例中给出的管道:

>>> text_clf = Pipeline([('vect', CountVectorizer()),
...                      ('tfidf', TfidfTransformer()),
...                      ('clf', MultinomialNB()),
... ])
Run Code Online (Sandbox Code Playgroud)

我用来GridSearchCV在参数网格上找到最佳估算器.

不过,我想获得我的训练与设定的列名get_feature_names()的方法CountVectorizer().如果没有CountVectorizer()在管道外实施,这可能吗?

NBa*_*ley 9

使用该get_params()功能,您可以访问管道的各个部分及其各自的内部参数.这是一个访问的例子'vect'

text_clf = Pipeline([('vect', CountVectorizer()),
                     ('tfidf', TfidfTransformer()),
                     ('clf', MultinomialNB())]
print text_clf.get_params()['vect']
Run Code Online (Sandbox Code Playgroud)

收益率(对我来说)

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)
Run Code Online (Sandbox Code Playgroud)

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