简体   繁体   English

是否限制R svm软件包e1071中支持向量的数量?

[英]Limit the number of support vectors in R svm package e1071?

I use the svm function in package e1071. 我在软件包e1071中使用了svm函数。 As far as I understand, svm basic functionality can separate two linearly separable classes with an hyperplane (Support vectors). 据我了解,svm的基本功能可以将两个线性可分离的类与一个超平面分开(支持向量)。 More advanced features allow you to perform numeric regressions and non-linear separation. 更高级的功能使您可以执行数值回归和非线性分离。 When I started testing it on some data I could not understand why the output of the model is a huge set of Support Vectors. 当我开始在某些数据上对其进行测试时,我无法理解为什么模型的输出是庞大的支持向量集。 When I ran it on some very simple test examples I got the same results. 当我在一些非常简单的测试示例上运行它时,我得到了相同的结果。 Here is an example: 这是一个例子:

X = rnorm(1000)
Y = rnorm(1000)
data = data.frame(X, Y, Z = as.factor(X + Y > 0))
model = svm(formula = Z ~ X + Y, data = data, kernel = "linear")

Here is the result: 结果如下:

Call:
svm(formula = Z ~ X + Y, data = data, kernel = "linear")


Parameters:
  SVM-Type:  C-classification 
SVM-Kernel:  linear 
  cost:  1 
  gamma:  0.5 

Number of Support Vectors:  102

This example is clearly linearly separable by only one Support Vector. 显然,此示例只能通过一个支持向量进行线性分离。 If not convinced you can run: 如果不确定,可以运行:

ggplot(data, aes(X, Y, col = Z)) + geom_point()

What is the meaning of the 102 Support Vectors? 102个支持向量的含义是什么? Why isn't the number of Support Vectors a parameter? 为什么支持向量的数量不是参数?

Thanks 谢谢

There is a distinction between a soft-margin and a hard-margin svm. 软保证金硬保证金 svm之间有区别。 This is controlled by the cost parameter which penalises the degree to which the support vectors are allowed to violate the margin constraint. 这由成本参数控制,该参数对支持向量违反边际约束的程度进行了惩罚。 So, you will get the minimal number of support vectors (which is three and not one) only in the case where your cost parameter is (very) large. 因此,仅在成本参数非常大的情况下,才能获得最少数量的支持向量(三个而不是一个)。 Try for example values for the cost parameter > 10000 and you will get three support vectors. 尝试例如cost参数的值> 10000,您将获得三个支持向量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM