【问题标题】:compare 3 model metrics with ggplot2将 3 个模型指标与 ggplot2 进行比较
【发布时间】:2021-01-05 01:36:57
【问题描述】:

当从 3 个训练模型绘制 3 个模型指标(RMSE、MAE、Rsquared)到测试集指标时,我试图证明神经网络模型是最好的

  • 训练和测试指标之间的距离最小
  • 它还具有足够低的 RSME/MAE 和高 Rsquared

现在从所附的情节中并不那么明显。此外,指标的尺度不同,因为 Rsquared 在 [0,1] 区间内。有没有办法更好地绘制它,最好在同一个图上?

> trn
            model RMSE Rsquared  MAE dataType
1      Linear Reg 9.17     0.51 6.03    train
2      SVM Radial 7.86     0.64 4.86    train
3 Neural Networks 8.55     0.57 5.59    train
> tst
            model RMSE Rsquared  MAE dataType
1      Linear Reg 9.40     0.53 5.95     test
2      SVM Radial 9.16     0.55 5.50     test
3 Neural Networks 8.66     0.60 5.48     test
> 

可重现的代码:

trn <- structure(list(model = c("Linear Reg", "SVM Radial", "Neural Networks"),
                      RMSE = c(9.17, 7.86, 8.55), Rsquared = c(0.51, 0.64, 0.57),
                      MAE = c(6.03, 4.86, 5.59)),
                 row.names = c(NA, -3L), class = "data.frame")

tst <- structure(list(model = c("Linear Reg", "SVM Radial", "Neural Networks"),
                      RMSE = c(9.4, 9.16, 8.66), Rsquared = c(0.53, 0.55, 0.6),
                      MAE = c(5.95, 5.5, 5.48)),
                 row.names = c(NA, -3L), class = "data.frame")

trn['dataType'] = 'train'
tst['dataType'] = 'test'

long_tbl <- rbind(trn, tst) %>%
  pivot_longer(cols =!c('model', 'dataType'), names_to = 'metric', values_to='value')

ggplot(long_tbl, aes(x=model, y=value, shape = dataType, colour = metric )) + 
  geom_point()

【问题讨论】:

    标签: r ggplot2 cross-validation


    【解决方案1】:

    最简单的方法是 + facet_wrap(~metric, scales="free"),但我认为这不能满足您“在一个情节中”的要求(它在一个情节中声明,但在三个子情节中)。如果gg1 是您的原始图,那么这是一种非常压缩的格式:

    print(gg1 
        + facet_wrap(~metric,scale="free_y",ncol=1) 
        + theme_bw() 
        + theme(panel.spacing=grid::unit(0,"lines"),
                 strip.background=element_blank(),strip.text.x=element_blank())
    )
    

    任何比这更压缩的东西都需要您做出一些关于丢弃哪些信息的决定(例如,您是否愿意将所有指标重新调整为 min=0、max=1,或者差异的大小是否传达了信息?

    保持条形标签完好无损可能会使图表更易于阅读(用户不必眯着眼睛看图例来确定哪个指标是哪个指标);你也可以试试moving the strip labels to the right edge

    【讨论】:

    • 太好了,我刚刚添加了axis.title = element_blank()。应该提到它正在进入rmarkdown 文档,在那里看起来很好,我刚刚测试过
    • 那行得通,如果你想将 x 轴和 y 轴标签都去掉,可以使用 +labs(x="",y="")(比设置主题稍微干净一些)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 2016-01-18
    相关资源
    最近更新 更多