Created
November 2, 2018 04:42
-
-
Save venik/bfdcf5a6be838b1c4b194a7dfde992d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = rbind(mvrnorm(50, rep(0,10), diag(10)), mvrnorm(50, rep(c(1, 0), c(5, 5)), diag(10))) | |
y = rep(c(0, 1), c(50, 50)) | |
dat = data.frame(x, y=as.factor(y)) | |
svmfit = svm(y~., data=dat) | |
ex1 = function (times, svmfit) { | |
errate = rep(0, times) | |
test_size = 500 | |
for (i in 1:times) { | |
test_x = rbind(mvrnorm(test_size, rep(0,10), diag(10)), mvrnorm(test_size, rep(c(1, 0), c(5, 5)), diag(10))) | |
test_y = rep(c(0, 1), c(test_size, test_size)) | |
pred = predict(svmfit, test_x) | |
tt = table(pred, test_y) | |
errate[i] = (tt[1, 2] + tt[2, 1]) / test_size | |
} | |
return(errate) | |
} | |
mean(ex1(100, svmfit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment