以下是代码:
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
出了什么问题?
答案 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作者感到遗憾的是,虽然...
指定了错误的参数,但没有上升异常