如何获得R中的平均总体精度和kappa统计
最近,我编写了一个脚本,用R中的randomForest软件包训练一个随机森林模型来分类土地利用/覆盖类型。当我运行脚本10次时,我将得到不同的总体精度和kappa统计数据。现在,我想用K-fold交叉验证重新训练我的模型,但我不知道如何做到这一点,如何找到一个最佳的模式?如果我使用K倍交叉验证重新训练我的模型,我如何才能得到平均的总体准确度和kappa统计 有没有人有一些经验或工作的例子?那将是非常感谢。非常感谢 我的代码如下:如何获得R中的平均总体精度和kappa统计,r,classification,random-forest,R,Classification,Random Forest,最近,我编写了一个脚本,用R中的randomForest软件包训练一个随机森林模型来分类土地利用/覆盖类型。当我运行脚本10次时,我将得到不同的总体精度和kappa统计数据。现在,我想用K-fold交叉验证重新训练我的模型,但我不知道如何做到这一点,如何找到一个最佳的模式?如果我使用K倍交叉验证重新训练我的模型,我如何才能得到平均的总体准确度和kappa统计 有没有人有一些经验或工作的例子?那将是非常感谢。非常感谢 我的代码如下: [enter link description here][1]
[enter link description here][1]
cat(“计算随机林对象\n”)
randfor你需要提供一个,以便人们帮助你。很抱歉。我将上载我的所有数据。谢谢。嗨,LyzandeR。如何上载.R脚本?我不能这样做。
cat("Calculating random forest object\n")
randfor <-randomForest(as.factor(response)~.,data=trainvals,importance=TRUE, na.action=na.omit,proximity=TRUE)
#try to print randomForest model and see the important features
print(randfor)
#Try to see the margin, positive or negative, if positive it means
#correct classification
rf.margin <- margin(randfor,responseTest)
plot(rf.margin)
#display the error rates of a randforForest
plot(randfor)
#Predict the land cover type of the test datasets
pred <- predict(randfor,newdata = trainvalsTest)
#generate a classification table for the testing datasets
rf.table <- table(pred,responseTest)
rf.table
# Plotting variable importance plot
varImpPlot(randfor)
classAgreement(rf.table)
#Print the value of overall accuracy and Kappa Statistic
confusion <- confusionMatrix(pred,responseTest)
confusion
#print the importance of all the input variables
randomForest.importance <- importance(randfor)
randomForest.importance
#using caret package to calculate the variable importance
caret.importance <- varImp(randfor,scale = FALSE)
#print the overalll value of the input variables
print(caret.importance)
#display the variable importance plot
plot(caret.importance)