我正在尝试使用 SVM 实现人体检测。我正在使用 HOG 特征提取,然后对其应用 SVM。当我应用线性 SVM 时,我会得到图像的分数,但在 RBF kernal SVM 中我只能得到 0 和 1。无论如何我可以获得检测分数吗?我怎样才能像线性SVM一样看到RBF核的系数?
我尝试了Python提供的SVM库。
[...] 在 RBF kernal SVM 中我只得到 0 和 1。无论如何我可以获得检测分数吗?
获得分数的一种方法是使用 SVC 的
.decision_function(X)
方法。它越大,该点距离决策平面越远(符号表示类别)。然而,它是一个无界值,可以任意大。
第二个选项是设置
SVC(probability=True, ...)
(probability=
参数默认为 False
),这样您就可以获取概率分数。运行时间会更长.fit()
。然后您可以使用 .predict_proba(X)
方法获得概率。
我怎样才能像线性SVM一样看到RBF核的系数?
您不能直接使用
SVC(kernel='rbf')
执行此操作。但是,您可以使用 kernel_approximation.RBFSampler
或 kernel_approximation.Nystroem
来近似 RBF 特征空间,然后将其管道化为 LinearSVC
。这将允许您访问近似 RBF 空间的系数。
from sklearn.kernel_approximation import Nystroem, RBFSampler
from sklearn.svm import LinearSVC
from sklearn.pipeline import make_pipeline
#np.random.seed(0) #makes example reproducible
rbf_svc_approx = make_pipeline(
Nystroem(kernel='rbf', n_components=100, n_jobs=-1),
LinearSVC(),
)
#Access coefficients corresponding to the 100-dimensional RBF feature space
rbf_coeffs = rbf_svc_approx['linearsvc'].coef_
您可能会在这里找到一些感兴趣的细节。