Skip to content

Instantly share code, notes, and snippets.

@venik venik/ch9_helper.r
Created Nov 2, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.