Last active
August 28, 2018 17:40
-
-
Save rebeccapeltz/89ae27d4210257f2f84be6e2872de5be to your computer and use it in GitHub Desktop.
r accuracy/r^2
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
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