如何在R语言的ggplot2中设置y轴以比较机器学习模型

我有一个机器学习模型准确率的数据集,我希望通过箱线图来进行比较,但我不知道如何将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()

enter image description here

Related Posts

在使用k近邻算法时,有没有办法获取被使用的“邻居”?

我想找到一种方法来确定在我的knn算法中实际使用了哪些…

Theano在Google Colab上无法启用GPU支持

我在尝试使用Theano库训练一个模型。由于我的电脑内…

准确性评分似乎有误

这里是代码: from sklearn.metrics…

Keras Functional API: “错误检查输入时:期望input_1具有4个维度,但得到形状为(X, Y)的数组”

我在尝试使用Keras的fit_generator来训…

如何使用sklearn.datasets.make_classification在指定范围内生成合成数据?

我想为分类问题创建合成数据。我使用了sklearn.d…

如何处理预测时不在训练集中的标签

已关闭。 此问题与编程或软件开发无关。目前不接受回答。…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注