Skip to content

Instantly share code, notes, and snippets.

@venik
Created November 2, 2018 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save venik/bfdcf5a6be838b1c4b194a7dfde992d6 to your computer and use it in GitHub Desktop.
Save venik/bfdcf5a6be838b1c4b194a7dfde992d6 to your computer and use it in GitHub Desktop.
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