2016-10-13 92 views
1

下面是代碼:伽瑪在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) 

在總結伽馬參數是不同的東西我設置:

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 

出了什麼問題?

回答

3

你只是拼錯了參數,仔細看看gammma,你看到多少個m?我花了一段時間才能看到,有超過2

嘗試在e1071作者

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) 

羞恥不漲例外,雖然指定的參數不正確......