1

我必须使用 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 语言的箱线图?

谢谢

4

1 回答 1

1

使用示例数据集:

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)

最好创建一个 data.frame,其中 MAE 和一个向量表示模型:

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()

在此处输入图像描述

于 2020-06-02T15:02:20.297 回答