【发布时间】:2015-12-17 22:35:43
【问题描述】:
如果我将 FeatureUnion 的 transformer_weights 设置为 0 会发生什么?我想知道我是否可以使用这种方法来选择退出 GridSearchCV 中的一组功能。通过这种方式,我可以利用 GridSearchCV 的交叉验证来测试一个特征是否能提高预测。
此外,任何关于不同模型如何对这个transformer_weights 变化做出反应的想法。我认为带平滑的 MultinationalNB 可以用来测试一组特征是否有用的想法。
(或者关于如何测试特征重要性的任何其他想法?我的另一个想法是做一个特征选择,看看'羽毛被测试'是否被各种特征选择方法丢弃。但另一方面,来自 GridSearchCV 的最佳估计器在保留数据集上的预测性能是一个“终极”测试,所以我仍然会使用这个测试而不是特征选择。)
这是一个带有 FeatureUnion 的示例管道。
pipeline = Pipeline([
# Use FeatureUnion to combine the features
('union', FeatureUnion(
transformer_list=[
# Pipeline for pulling features from the post's subject line
('subject', Pipeline([
('selector', ItemSelector(key='subject')),
('tfidf', TfidfVectorizer(min_df=50)),
])),
# Pipeline for standard bag-of-words model for body
('body_bow', Pipeline([
('selector', ItemSelector(key='body')),
('tfidf', TfidfVectorizer()),
('best', TruncatedSVD(n_components=50)),
])),
],
# weight components in FeatureUnion
transformer_weights={
'body_bow': 1.0,
'subject': 0.0,
},
)),
('svc', SVC(kernel='linear')),
])
可以找到来自 Matt Terry 的完整示例here:
【问题讨论】:
标签: python machine-learning scikit-learn artificial-intelligence