这是一个不安全感,我与sk-学习的管道。每当我在sk中创建一个管道-学习并使用这个管道做一些预测,我似乎遇到了一个问题,我不能实际检查管道的中间步骤。预测是可行的,我得到了我的分数,但是如果我想获得实例中的“特性重要性”,或者检查TF-下手向量器的特性是什么,则声称管道不合适(即使它是最近用于推理的,而且我已经对它进行了培训)。
举个例子,从Scikit- 这里的文档中调用以下代码片段的这里可以进行预测,但是当我想检查管道的tfidf时,它声称同样的不合适的问题。
pipeline = Pipeline([
# Extract the subject & body
('subjectbody', SubjectBodyExtractor()),
# Use ColumnTransformer to combine the features from subject and body
('union', ColumnTransformer(
[
# Pulling features from the post's subject line (first column)
('subject', TfidfVectorizer(min_df=50), 0),
# Pipeline for standard bag-of-words model for body (second column)
('body_bow', Pipeline([
('tfidf', TfidfVectorizer()),
('best', TruncatedSVD(n_components=50)),
]), 1),
# Pipeline for pulling ad hoc features from post's body
('body_stats', Pipeline([
('stats', TextStats()), # returns a list of dicts
('vect', DictVectorizer()), # list of dicts -> feature matrix
]), 1),
],
# weight components in ColumnTransformer
transformer_weights={
'subject': 0.8,
'body_bow': 0.5,
'body_stats': 1.0,
}
)),
# Use a SVC classifier on the combined features
('svc', LinearSVC(dual=False)),
], verbose=True)在将管道安装在数据上(如在链接中所做的那样)之后,当我尝试使用
pipeline.named_steps.union.transformers[1][1].named_steps['tfidf'].get_feature_names() 它声称“词汇不符合或不提供”。
所以,这是我对管道的误解吗?我们不应该进入中间的步骤吗?或者需要设置一个设置?
发布于 2021-02-24 08:03:46
你需要通过.transformers_来访问变压器,所以pipeline.named_steps.union.transformers_[1][1].named_steps['tfidf'].get_feature_names()
https://stackoverflow.com/questions/61225065
复制相似问题