ڷ HOME > ڷ > ڷ
 
[Ȱ뿬] SVM sampling Rڵ
16-05-24 11:05 1,164
 
## 10-fold cross-validation Ž
// ͸ Ѵ.
  // "kernlab" Ű spam ͸ ҷ´.
  install.packages("kernlab")
  library(kernlab)
  data(spam)
// üڷḦ 3:1 Ѵ. (н : )
  n      <- nrow(spam)
  sub    <- sample(1:n , round(0.75 * n)) # 1°~n° ġ 3:1 . (replace ɼ Ʈ FALSE ̴.)
  spam.1 <- spam[ sub, ]
  spam.2 <- spam[-sub, ]
// svm() Լ gamma cost ٸ θ ٸ Ÿ ִ.
// e1071 Ű tune.svm() SVM Ķ͸ ãƺ.
// Լ 10- Ÿ缺 (10-fold cross-validation) .
//   gamma 0.1, 1 , 10
//   cost  0.1, 1 , 10
// 9 ߿ (gamma, cost) ãƺ.
  // 10-fold cross-validation ϴ tune()Լ
  install.packages("e1071")
  library(e1071)
  tune.svm <- tune(svm, type~. , data= spam.1 , ranges= list(gamma=c(0.1 , 1 , 10) , cost=c(0.1 , 1 , 10))) # ð ɸ
  summary(tune.svm)
// ð ˾ƺ. (847)