Gamma在径向内核的SVM中发生了变化

时间:2016-10-13 19:22:45

标签: r svm

以下是代码:

library(e1071)
set.seed(1)
x = matrix(rnorm(200 * 2), ncol = 2)
x[1:100, ] = x[1:100, ] + 2 
x[101:150, ] = x[101:150, ] - 2 
y = c(rep(1, 150), rep(2, 50))
dat = data.frame(x = x, y = as.factor(y))
head(dat)
plot(x, col = y)
train = sample(200, 100)
svmfit = svm(y ~ ., data = dat[train, ], kernel = "radial", gammma = 1, cost = 1)
plot(svmfit, dat[train, ])
summary(svmfit)

摘要中的gamma参数与我设置的不同:

Call:
svm(formula = y ~ ., data = dat[train, ], kernel = "radial", gammma = 1, cost = 1)


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

Number of Support Vectors:  36

 ( 18 18 )


Number of Classes:  2 

Levels: 
 1 2

出了什么问题?

1 个答案:

答案 0 :(得分:3)

您只是错误拼写参数,仔细查看gammma,您看到了多少m?我花了一段时间才发现有超过2个。

尝试

library(e1071)
set.seed(1)
x = matrix(rnorm(200 * 2), ncol = 2)
x[1:100, ] = x[1:100, ] + 2 
x[101:150, ] = x[101:150, ] - 2 
y = c(rep(1, 150), rep(2, 50))
dat = data.frame(x = x, y = as.factor(y))
head(dat)
plot(x, col = y)
train = sample(200, 100)
svmfit = svm(y ~ ., data = dat[train, ], kernel = "radial", gamma = 1, cost = 1)
plot(svmfit, dat[train, ])
summary(svmfit)

e1071作者感到遗憾的是,虽然...

指定了错误的参数,但没有上升异常