从Scikit(Python)中的管道检索中间特征 [英] retrieve intermediate features from a pipeline in Scikit (Python)

查看:101
本文介绍了从Scikit(Python)中的管道检索中间特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的管道与在此示例中:

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

我使用GridSearchCV在参数网格上找到最佳估计量.

over which I use GridSearchCV to find the best estimators over a parameter grid.

但是,我想通过CountVectorizer()get_feature_names()方法获取训练集的列名.如果不在管道外部实现CountVectorizer(),这是否可能?

However, I would like to get the column names of my training set with the get_feature_names() method from CountVectorizer(). Is this possible without implementing CountVectorizer() outside the pipeline?

推荐答案

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

Using the get_params() function, you can get access at the various parts of the pipeline and their respective internal parameters. Here's an example of accessing '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()将返回错误.

I haven't fitted the pipeline to any data in this example, so calling get_feature_names() at this point will return an error.

这篇关于从Scikit(Python)中的管道检索中间特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆