如何获取特征的权重 [英] How to obtain features' weights
问题描述
我正在处理高度不平衡的数据集,我的想法是从我的 libSVM 模型中获取特征权重的值.至于现在我对线性内核没问题,在那里我可以获得特征权重,但是当我使用 rbf
或 poly
时,我无法达到我的目标.>
这里我使用 sklearn
作为我的模型,使用 .coef_
很容易获得线性核的特征权重.谁能帮我为 rbf
或 poly
做同样的事情?到目前为止,我尝试做的事情如下:
svr = SVC(C=10, cache_size=200, class_weight='auto', coef0=0.0, degree=3.0, gamma=0.12,kernel='rbf', max_iter=-1,probability=True, random_state=0,shrinking=True, tol=0.001,verbose=False)clf = svr.fit(data_train,target_train)打印 clf.coef_
这不仅是不可能的,正如 文档:
<块引用>分配给特征的权重(原始问题中的系数).这仅在线性核的情况下可用.
但也没有意义.在线性 SVM 中,生成的分离平面与输入特征在同一空间中.因此,它的系数可以看作是输入维度"的权重.
在其他核中,分离平面存在于另一个空间——原始空间核变换的结果.它的系数与输入空间没有直接关系.事实上,对于 rbf
内核,变换后的空间是无限维的(你可以从这个 当然是在维基百科上).
I am dealing with highly imbalanced data set and my idea is to obtain values of feature weights from my libSVM model. As for now I am OK with the linear kernel, where I can obtain feature weights, but when I am using rbf
or poly
, I fail to reach my objective.
Here I am using sklearn
for my model and it's easy to obtain feature weights for linear kernel using .coef_
. Can anyone help me to do same thing for rbf
or poly
? What I've tried to do so far is given below:
svr = SVC(C=10, cache_size=200, class_weight='auto', coef0=0.0, degree=3.0, gamma=0.12,kernel='rbf', max_iter=-1, probability=True, random_state=0,shrinking=True, tol=0.001, verbose=False)
clf = svr.fit(data_train,target_train)
print clf.coef_
This is not only impossible, as stated in the documentation:
Weights asigned to the features (coefficients in the primal problem). This is only available in the case of linear kernel.
but also it doesn't make sense. In linear SVM the resulting separating plane is in the same space as your input features. Therefore its coefficients can be viewed as weights of the input's "dimensions".
In other kernels, the separating plane exists in another space - a result of kernel transformation of the original space. Its coefficients are not directly related to the input space. In fact, for the rbf
kernel the transformed space is infinite-dimensional (you can get a starting point on this on Wikipedia of course).
这篇关于如何获取特征的权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!