机器学习包(如liblinear和nltk)中的分类器提供了一种方法show_most_informative_features()
,这对调试特性非常有帮助:
viagra = None ok : spam = 4.5 : 1.0
hello = True ok : spam = 4.5 : 1.0
hello = None spam : ok = 3.3 : 1.0
viagra = True spam : ok = 3.3 : 1.0
casino = True spam : ok = 2.0 : 1.0
casino = None ok : spam = 1.5 : 1.0
我的问题是是否在scikit learn中为分类器实现了类似的功能。我搜索了文件,但找不到类似的东西。
如果还没有这样的函数,有人知道如何获得这些值的解决方法吗?
多谢!
要添加更新,
RandomForestClassifier
现在支持.feature_importances_
属性。这个attribute告诉您观察到的方差有多少是由这个特性解释的。显然,所有这些值的和必须是<;=1。我发现这个属性在执行特征工程时非常有用。
感谢scikit学习团队和贡献者实现了这一点!
编辑:这对RandomForest和GradientBoosting都有效。所以
RandomForestClassifier
、RandomForestRegressor
、GradientBoostingClassifier
和GradientBoostingRegressor
都支持这一点。分类器本身不记录要素名称,只看到数字数组。但是,如果使用
Vectorizer
/CountVectorizer
/TfidfVectorizer
/DictVectorizer
,和提取特征,则使用线性模型(例如LinearSVC
或Naive Bayes),则可以应用document classification example使用的相同技巧。示例(未测试的可能包含一个或两个错误):这是用于多类分类的;对于二进制情况,我认为应该只使用
clf.coef_[0]
。您可能需要对class_labels
进行排序。在larsmans代码的帮助下,我想出了这个二进制代码:
相关问题 更多 >
编程相关推荐