Skip to content

Instantly share code, notes, and snippets.

@rebeccapeltz
Last active August 28, 2018 17:40
Show Gist options
  • Save rebeccapeltz/89ae27d4210257f2f84be6e2872de5be to your computer and use it in GitHub Desktop.
Save rebeccapeltz/89ae27d4210257f2f84be6e2872de5be to your computer and use it in GitHub Desktop.
r accuracy/r^2
sstot = sum((credit$R1 - mean(credit$R1))^2)
totsse =0
accuracy = rep(0,nrow(credit))
r2 = 0
#cross validate nfold leave one out
for (i in 1:nrow(credit)){
# print(i)
model.svm = svm(R1 ~ ., data=credit[-i,])
pred.svm = sapply(predict(model.svm,credit[i,]),roundOff)
# print(paste("pred",pred.svm))
totsse = totsse + ((pred.svm - credit[i,11])^2)
r2 = 1-totsse/sstot
accuracy[i] = pred.svm == credit[i,11]
}
(acc=sum(accuracy)/nrow(credit))
print(paste("Average accuracy with n fold cv for svn classification is:",round(acc,digits=2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment