从Scikit(Python)中的管道检索中间特性
我使用的管道与给出的管道非常相似: 在此基础上,我使用从Scikit(Python)中的管道检索中间特性,python,scikit-learn,pipeline,Python,Scikit Learn,Pipeline,我使用的管道与给出的管道非常相似: 在此基础上,我使用GridSearchCV查找参数网格上的最佳估计量 但是,我想使用CountVectorizer()中的get\u feature\u names()方法获取我的训练集的列名。如果不在管道外部实现CountVectorizer(),这是否可行?使用get_params()函数,您可以访问管道的各个部分及其各自的内部参数。下面是访问'vect' text_clf = Pipeline([('vect', CountVectorizer()),
GridSearchCV
查找参数网格上的最佳估计量
但是,我想使用CountVectorizer()
中的get\u feature\u names()
方法获取我的训练集的列名。如果不在管道外部实现CountVectorizer()
,这是否可行?使用get_params()
函数,您可以访问管道的各个部分及其各自的内部参数。下面是访问'vect'
text_clf = Pipeline([('vect', CountVectorizer()),
('tfidf', TfidfTransformer()),
('clf', MultinomialNB())]
print text_clf.get_params()['vect']
收益率(对我而言)
countvectorier(分析器=u'word',二进制=False,解码错误=u'strict',
数据类型=,编码=u'utf-8',输入=u'content',
小写=真,最大值为1.0,最大值为无,最小值为1,
ngram_范围=(1,1),预处理器=无,停止字=无,
strip\u accents=None,token\u pattern=u'(?u)\\b\\w\\w+\\b',
标记器=无,词汇表=无)
在本例中,我没有将管道安装到任何数据,因此此时调用get\u feature\u names()
将返回错误 仅供参考
The estimators of a pipeline are stored as a list in the steps attribute:
>>>
>>> clf.steps[0]
('reduce_dim', PCA(copy=True, n_components=None, whiten=False))
and as a dict in named_steps:
>>>
>>> clf.named_steps['reduce_dim']
PCA(copy=True, n_components=None, whiten=False)
从
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)
The estimators of a pipeline are stored as a list in the steps attribute:
>>>
>>> clf.steps[0]
('reduce_dim', PCA(copy=True, n_components=None, whiten=False))
and as a dict in named_steps:
>>>
>>> clf.named_steps['reduce_dim']
PCA(copy=True, n_components=None, whiten=False)