带统计 (wilcoxon) 检验的箱线图

Boxplots with the statistical (wilcoxon) test

我必须使用 caret R 包比较不同的 ML 算法,然后找出这些算法之间的显着差异。

例如,我使用我的代码如下

nnet2 <- train(result ~ ., data = tr,
              method = "nnet",
               tuneLength = 15,
              metric = "MAE",
              preProc = c("center", "scale", "nzv"),
              trControl = ctrl)

getTrainPerf(nnet2)

svm2 <- train(result ~ ., data = tr,
             method = "svmRadial",

             tuneLength = 15,
             metric = "MAE",
             preProc = c("center", "scale", "nzv"),
             trControl = ctrl)

getTrainPerf(svm2)

和其他类似的算法很少。然后我进行了 wilcoxon 测试

wilcox.test (nnet2$resample$MAE, svm2$resample$MAE, paired=T)

我的问题是如何将 wilcoxon 检验的结果作为 R 语言中的箱线图?

谢谢

使用示例数据集:

library(caret)
library(mlbench)
library(ggpubr)
data(BostonHousing)
tr = BostonHousing

ctrl = trainControl(method="cv",number=10)

nnet2 <- train(medv ~ ., data = tr,
              method = "nnet",
               tuneLength = 5,
              metric = "MAE",
              preProc = c("center", "scale", "nzv"),
              trControl = ctrl)

svm2 <- train(medv ~ ., data = tr,
             method = "svmRadial",

             tuneLength = 5,
             metric = "MAE",
             preProc = c("center", "scale", "nzv"),
             trControl = ctrl)

最好用 MAE 和表示模型的向量创建 data.frame:

df = data.frame(MAE=c(nnet2$resample$MAE,svm2$resample$MAE),
model=rep(c("nnet","svm"),each=length(svm2$resample$MAE)))

ggboxplot(df, x = "model",y= "MAE",col="model",palette = c("#00AFBB", "#E7B800")) + 
stat_compare_means()