我发现kernlab软件包的行为令人困惑:在数学上相同的SVM估计在软件中会产生不同的结果。
这段代码片段只是将鸢尾花数据转换为二元分类问题,为了简单起见。正如您所看到的,我在两个SVM中都使用线性核函数。
我的问题是,kernlab软件包中是否存在任何已知的错误,可以解释这种异常行为。
(Kernlab for R是一种SVM求解器,允许使用多个预装的核函数或用户提供的核矩阵。输出是对用户提供的超参数的支持向量机的估计。)
这段代码片段只是将鸢尾花数据转换为二元分类问题,为了简单起见。正如您所看到的,我在两个SVM中都使用线性核函数。
library(kernlab)
library(e1071)
data(iris)
x <- as.matrix(iris[, 1:4])
y <- as.factor(ifelse(iris[, 5] == 'versicolor', 1, -1))
C <- 5.278031643091578
svm1 <- ksvm(x = x, y = y, scaled = FALSE, kernel = 'vanilladot', C = C)
K <- kernelMatrix(vanilladot(), x)
svm2 <- ksvm(x = K, y = y, C = C, kernel = 'matrix')
svm3 <- svm(x = x, y = y, scale = FALSE, kernel = 'linear', cost = C)
然而,svm1和svm2的总结信息显著不同:kernlab报告这两个模型之间存在完全不同的支持向量数、训练误差率和目标函数值。
> svm1
Support Vector Machine object of class "ksvm"
SV type: C-svc (classification)
parameter : cost C = 5.27803164309158
Linear (vanilla) kernel function.
Number of Support Vectors : 89
Objective Function Value : -445.7911
Training error : 0.26
> svm2
Support Vector Machine object of class "ksvm"
SV type: C-svc (classification)
parameter : cost C = 5.27803164309158
[1] " Kernel matrix used as input."
Number of Support Vectors : 59
Objective Function Value : -292.692
Training error : 0.333333
为了比较,我也使用e1071计算了相同的模型,它提供了libsvm包的R接口。
svm3
Call:
svm.default(x = x, y = y, scale = FALSE, kernel = "linear", cost = C)
Parameters:
SVM-Type: C-classification
SVM-Kernel: linear
cost: 5.278032
gamma: 0.25
Number of Support Vectors: 89
It reports 89 support vectors, the same as svm1.
我的问题是,kernlab软件包中是否存在任何已知的错误,可以解释这种异常行为。
(Kernlab for R是一种SVM求解器,允许使用多个预装的核函数或用户提供的核矩阵。输出是对用户提供的超参数的支持向量机的估计。)