ããã¯ååã®è¨äºã®è£è¶³ã§ãã
ããè¦ãã¾ãã¾ã§ããããã1ã¯ã©ã¹SVMã®æ±ºå®å¢çãå ·ä½çã«æç»ãã¦ã¿ããã©ããªããã ããï¼ãã¨ããèå³ãæã£ãã®ã§ã漫ç¶ã¨2次å ã§ãã£ã¦ã¿ã¾ããååã®è¨äºåæ§ã1ã¯ã©ã¹SVMã®æ¨å®ã«ç¨ããã®ã¯{e1071}ããã±ã¼ã¸ã®svmé¢æ°ã§ãtype = 'one-classification'ã¨æå®ããå ´åãã«ã¼ãã«ã¯ã¬ã¦ã·ã¢ã³ã§ãã
ãªã{e1071}ã®vignetteã«ãæ¸ããã¦ãã¾ããã1ã¯ã©ã¹SVM (-SVM)ã®ä¸»åé¡ãããããããã¨ä»¥ä¸ã®éãã§ãã
ã大ããï¼å°ããï¼ãããã¨ã§ãã®åããç¯å²ãçãï¼åºãï¼ãªããã¨ãè¦ã¦åãã¾ããä¸è¬ã«ã®å¤ã¯å¦ç¿ãã¼ã¿ãã®ãã®ã«åé¡å¨ãé©ç¨ããå ´åã®é°æ§çã«è¿ããªããããã®ã§ãä¾ãã°0.01ã¨ãã«ããã¨é°æ§çã1%ãéã«0.99ã¨ãã«ããã¨å¤§åãé°æ§ã¨ãããã¨ã«ãªãããã§ãã
é©å½ã«ãã¼ã¿ã»ãããä½ã
> set.seed(101) > tmp1 <- rnorm(1000,0,1) > set.seed(102) > tmp2 <- rnorm(1000,0,1) > d <- data.frame(x=tmp1, y=tmp2) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4))
å®å
¨ã«é©å½ã§ãã
tune.svmã§å®ãããã©ã¡ã¼ã¿ã«åºã¥ãã¦ãã£ã¦ã¿ã
> library(e1071) > tuned <- tune.svm(x=d, y=rep(TRUE, nrow(d)), type='one-classification', kernel='radial', gamma=1e-3:1, nu=1e-2:1) > tuned$best.parameters gamma nu 1 0.001 0.01 > d.svm <- svm(x=d, y=NULL, type='one-classification', kernel='radial', gamma=tuned$best.parameters$gamma, nu=tuned$best.parameters$nu) > px <- seq(-4,4,0.05) > py <- seq(-4,4,0.05) > pgrid <- expand.grid(px,py) > names(pgrid) <- names(d) > pred <- predict(d.svm, newdata=pgrid) > pred.num <- as.integer(pred) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4), xlab='', ylab='') > par(new=T) > contour(px, py, array(pred.num, dim=c(length(px),length(py))), levels=0.5, labels = '', xlim=c(-4,4), ylim=c(-4,4), lwd=5, col='red')
ããæãã«è¦ãã¾ãããå¤å°å¦ç¿ãã¼ã¿ãã®ãã®ã«ãç°å¸¸å¤ã¨å¤å®ããã¦ãããµã³ãã«ãç®ã«ã¤ãã¾ããã
é©å½ã«æã§ããã£ã¦ã¿ã
ä¸è¨ã®æ±ºå®å¢çã«å¯¾ãã¦ããã©ã¡ã¼ã¿ãå¤ããã¨ã©ã®ãããªå½±é¿ãåºãããè¦ã¦ã¿ã¾ããã¾ããnuã10ã§å²ã£ã¦ã¿ã¾ããã大ããå´ã¾ã§è¨±å®¹ãããããã«ãªãã¯ãã§ãã
> d.svm <- svm(x=d, y=NULL, type='one-classification', kernel='radial', gamma=tuned$best.parameters$gamma, nu=tuned$best.parameters$nu/10) > pred <- predict(d.svm, newdata=pgrid) > pred.num <- as.integer(pred) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4), xlab='', ylab='') > par(new=T) > contour(px, py, array(pred.num, dim=c(length(px),length(py))), levels=0.5, labels = '', xlim=c(-4,4), ylim=c(-4,4), lwd=5, col='red')
1ã¤ã®ãµã³ãã«ãé¤ããå ¨ã¦ã®ãµã³ãã«ã決å®å¢çå ã«åã¾ãã¾ããã
ä»åº¦ã¯éã«1 - nuãã¦ã¿ã¾ãããã
> d.svm <- svm(x=d, y=NULL, type='one-classification', kernel='radial', gamma=tuned$best.parameters$gamma, nu=1-tuned$best.parameters$nu) > pred <- predict(d.svm, newdata=pgrid) > pred.num <- as.integer(pred) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4), xlab='', ylab='') > par(new=T) > contour(px, py, array(pred.num, dim=c(length(px),length(py))), levels=0.5, labels = '', xlim=c(-4,4), ylim=c(-4,4), lwd=5, col='red')
ãã²ãã²ããã»ã¼å ¨ã¦ãç°å¸¸å¤ã«ãªã£ã¦ãã¾ãã¾ããï¼æ±ï¼ããã¯ãnuã¯å°ãããªãã¨ãã¡ã¿ããã§ããã
念ã®ãããnuã100ã§å²ã£ãå¤ã«ãã¦ã¿ã¾ãã
> d.svm <- svm(x=d, y=NULL, type='one-classification', kernel='radial', gamma=tuned$best.parameters$gamma, nu=tuned$best.parameters$nu/100) > pred <- predict(d.svm, newdata=pgrid) > pred.num <- as.integer(pred) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4), xlab='', ylab='') > par(new=T) > contour(px, py, array(pred.num, dim=c(length(px),length(py))), levels=0.5, labels = '', xlim=c(-4,4), ylim=c(-4,4), lwd=5, col='red')
ããããä¸å¿ãããããæå¥å¦ç¿ãã¼ã¿ã®é°æ§çãä¸ãã£ã¦ãã¾ã£ãæ°ããã¾ãããã
ä»åº¦ã¯nuãbest parameterã10ã§å²ã£ãå¤ï¼ä¸è¨ã®ããã«ã»ã¼å ¨ã¦ã®ãµã³ãã«ãé½æ§ã«ãªãï¼ã«åºå®ãã¦ãã«ã¼ãã«å´ãããã£ã¦ã¿ã¾ããããã¾ããgammaã1000åãã¦ã¿ã¾ããéå¦ç¿æ°å³ã«ãªãã¯ãã§ãã
> d.svm <- svm(x=d, y=NULL, type='one-classification', kernel='radial', gamma=tuned$best.parameters$gamma*1000, nu=tuned$best.parameters$nu/10) > pred <- predict(d.svm, newdata=pgrid) > pred.num <- as.integer(pred) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4), xlab='', ylab='') > par(new=T) > contour(px, py, array(pred.num, dim=c(length(px),length(py))), levels=0.5, labels = '', xlim=c(-4,4), ylim=c(-4,4), lwd=5, col='red')
ããã¼ãæ°æã¡æªã決å®å¢çã«ãªãã¾ããï¼ç¬ï¼ãçãä¸ã«å¤§ç©´ãããã¤ã空ãã¦ãå¤ã¦ããªé°æ§å¤å®ã«ãªã£ã¦ãã¾ã£ã¦ãã¾ãã
ä»åº¦ã¯ãgammaã10000ã§å²ã£ã¦ã¿ã¾ããéã«æ±åãå¼·ããªãã¯ãã§ãã
> d.svm <- svm(x=d, y=NULL, type='one-classification', kernel='radial', gamma=tuned$best.parameters$gamma/10000, nu=tuned$best.parameters$nu/10) > pred <- predict(d.svm, newdata=pgrid) > pred.num <- as.integer(pred) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4), xlab='', ylab='') > par(new=T) > contour(px, py, array(pred.num, dim=c(length(px),length(py))), levels=0.5, labels = '', xlim=c(-4,4), ylim=c(-4,4), lwd=5, col='red')
ããï¼ããã¯nuã100ã§å²ã£ãæã¨åã決å®å¢çã«è¦ãã¾ããã¨ãããã¨ã¯ãããããããããã
ããã§ãgammaã¨nuãã§å²ã£ãå¤å士ã«ãã¦ã¿ã¾ãã
> d.svm <- svm(x=d, y=NULL, type='one-classification', kernel='radial', gamma=tuned$best.parameters$gamma/sqrt(10), nu=tuned$best.parameters$nu/sqrt(10)) > pred <- predict(d.svm, newdata=pgrid) > pred.num <- as.integer(pred) > plot(d, pch=19, cex=0.5, xlim=c(-4,4), ylim=c(-4,4), xlab='', ylab='') > par(new=T) > contour(px, py, array(pred.num, dim=c(length(px),length(py))), levels=0.5, labels = '', xlim=c(-4,4), ylim=c(-4,4), lwd=5, col='red')
ã´ã£ããä¸ç·ã¨ã¾ã§ã¯è¨ãã¾ããããnuã10ã§å²ã£ãæã¨ããä¼¼ãçµæã«ãªãã¾ããããããããããgammaã¨nuã¨ã®éã«ã¯ä½ãããã®ãã¬ã¼ããªãçãªé¢ä¿ãï¼ä¸»åé¡ã®å¼ããã¯åã¯ãã³ã¨æ¥ãªãã®ã§ããï¼ããã®ããããã¾ããã
ã¨ãããæãã®é©å½ãªå®é¨è¨é²ã§ããã