确定sklearn中SVM分类器最有帮助的功能 [英] Determining the most contributing features for SVM classifier in sklearn

查看:230
本文介绍了确定sklearn中SVM分类器最有帮助的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集,我想在该数据上训练我的模型.训练后,我需要了解SVM分类器分类的主要贡献者.

I have a dataset and I want to train my model on that data. After training, I need to know the features that are major contributors in the classification for a SVM classifier.

森林算法有一种叫做特征重要性的东西,有没有类似的东西?

There is something called feature importance for forest algorithms, is there anything similar?

推荐答案

是的,SVM分类器具有属性coef_,但仅适用于具有线性核的SVM.对于其他内核,这是不可能的,因为数据是通过内核方法转换到与输入空间无关的另一个空间的,请检查

Yes, there is attribute coef_ for SVM classifier but it only works for SVM with linear kernel. For other kernels it is not possible because data are transformed by kernel method to another space, which is not related to input space, check the explanation.

from matplotlib import pyplot as plt
from sklearn import svm

def f_importances(coef, names):
    imp = coef
    imp,names = zip(*sorted(zip(imp,names)))
    plt.barh(range(len(names)), imp, align='center')
    plt.yticks(range(len(names)), names)
    plt.show()

features_names = ['input1', 'input2']
svm = svm.SVC(kernel='linear')
svm.fit(X, Y)
f_importances(svm.coef_, features_names)

该函数的输出如下所示:

And the output of the function looks like this:

这篇关于确定sklearn中SVM分类器最有帮助的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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