59 名前:名無しさん@5周年 mailto:sage [2006/07/26(水) 17:11:39 ] >>57-58 激サンクス!うまいこと超平面からの距離得られたよ。 ついでにSVにマークも付けておいた。 これでだいぶ分かりやすいプロット画面になったかと。 conplot.svm2d <-function(x, label, resol=c(100,100), ...) { rx <- range(x[,1])*1.2 ry <- range(x[,2])*1.2 tx <- seq(rx[1], rx[2], len=resol[1]) ty <- seq(ry[1], ry[2], len=resol[2]) grd <- expand.grid(tx, ty) model <- svm(x, label, ...) pred <- predict(model, grd, decision.values=T) hmap <- matrix(attr(pred, "decision.values"), resol[1], resol[2]) image(tx, ty, hmap, xlab="", ylab="", col=heat.colors(40)) contour(tx, ty, hmap, level=-1:1, drawlabels=F, lty=c(3,1,3), add=T) points(x[label == unique(label)[1],], pch=21, bg="black") points(x[label == unique(label)[2],], pch=21, bg="white") points(x[model$index,], cex=1.6) title("SVM - 2D plot (e1071)", family="serif") box() invisible(model) } ## Example2: Circle in a Square Problem # library(mlbench) # train <- mlbench.circle(100) # conplot.svm2d(train$x, train$cl, kernel="rad", type="C", gamma=4)