如何在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-means聚类方法中使用kmeans.fit函数?

我在一个视频中使用K-means聚类技术,但我不明白为…

如何获取Keras中ImageDataGenerator的.flow_from_directory函数扫描的类名?

我想制作一个用户友好的GUI图像分类器,用户只需指向数…

如何查看每个词的tf-idf得分

我试图了解文档中每个词的tf-idf得分。然而,它只返…

如何修复 ‘ValueError: Found input variables with inconsistent numbers of samples: [32979, 21602]’?

我在制作一个用于情感分析的逻辑回归模型时遇到了这个问题…

如何向神经网络输入两个不同大小的输入?

我想向神经网络输入两个数据集。第一个数据集(元素)具有…

逻辑回归与机器学习有何关联

我们正在开会讨论聘请一位我们信任的顾问来做机器学习。一…

发表回复

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