随机森林
library(randomForest)
set.seed(1234)
fit
fit
importance(fit,type=2)
fitpred
fitperf
dnn=c("Actual","Predict"))
fitperf
支持向量机
library(e1071)
set.seed(1234)
fit.svm
fit.svm
#选择调和参数
set.seed(1234)
tuned
tuned
fit.svm
svm.pred
svm.perf
dnn=c("Actual","Predicted"))
svm.perf
#检验精确度
performance
if(!all(dim(table)==c(2,2)))
stop("Must be a 2 x 2 table")
tn
fp
fn
tp
sensitivity
specificity
ppp
npp
hitrate
result
"\nspecificity = ",round(specificity,n),
"\nPositive Predictive Value = ",round(ppp,n),
"\nNegative Predictive Value = ",round(npp,n),
"\nAccuracy = ",round(hitrate,n),"\n",sep=" ")
cat(result)
}
performance(svm.perf)