我有一个机器学习模型准确率的数据集,我希望通过箱线图来进行比较,但我不知道如何将y轴设置为准确率。
我的数据是模型在每次交叉验证中的准确率:
Model 1 2 3 4 5 6 7 8 9 10LR 0.69047619 0.71428571 0.61904762 0.57142857 0.69047619 0.69047619 0.73809524 0.76190476 0.78571429 0.76190476SVM 0.80952381 0.76190476 0.76190476 0.76190476 0.80952381 0.76190476 0.78571429 0.76190476 0.88095238 0.88095238RF 0.73809524 0.61904762 0.52380952 0.61904762 0.73809524 0.71428571 0.73809524 0.71428571 0.88095238 0.71428571GBM 0.83333333 0.83333333 0.73809524 0.73809524 0.78571429 0.83333333 0.80952381 0.80952381 0.88095238 0.85714286MLP 0.85714286 0.80952381 0.80952381 0.76190476 0.78571429 0.83333333 0.76190476 0.92857143 0.92857143 0.85714286Keras 0.9047619 0.85714286 0.80952381 0.85714286 0.83333333 0.78571429 0.88095238 0.92857143 0.88095238 0.92857143
我尝试过:
accuracy <- c(0,1)p <- ggplot(bxplt, aes(Model, accuracy))p + geom_boxplot()Error: Aesthetics must be either length 1 or the same as the data (6): y
我觉得自己可能忽略了一些显而易见的东西,但我找不到任何足够相似的问题或具有类似示例的资源,任何帮助将不胜感激。
dput(bxplt)structure(list(Model = structure(c(3L, 6L, 5L, 1L, 4L, 2L), .Label = c("GBM", "Keras", "LR", "MLP", "RF", "SVM"), class = "factor"), X1 = c(0.69047619, 0.80952381, 0.73809524, 0.83333333, 0.85714286, 0.9047619), X2 = c(0.71428571, 0.76190476, 0.61904762, 0.83333333, 0.80952381, 0.85714286), X3 = c(0.61904762, 0.76190476, 0.52380952, 0.73809524, 0.80952381, 0.80952381), X4 = c(0.57142857, 0.76190476, 0.61904762, 0.73809524, 0.76190476, 0.85714286), X5 = c(0.69047619, 0.80952381, 0.73809524, 0.78571429, 0.78571429, 0.83333333), X6 = c(0.69047619, 0.76190476, 0.71428571, 0.83333333, 0.83333333, 0.78571429), X7 = c(0.73809524, 0.78571429, 0.73809524, 0.80952381, 0.76190476, 0.88095238 ), X8 = c(0.76190476, 0.76190476, 0.71428571, 0.80952381, 0.92857143, 0.92857143), X9 = c(0.78571429, 0.88095238, 0.88095238, 0.88095238, 0.92857143, 0.88095238), X10 = c(0.76190476, 0.88095238, 0.71428571, 0.85714286, 0.85714286, 0.92857143 )), class = "data.frame", row.names = c(NA, -6L))
回答:
你应该重塑你的数据框:
library(tidyverse)df %>% gather(key = "fold", value = "accuracy", -Model) %>% ggplot(aes(Model, accuracy)) + geom_boxplot()