r - 如何以概率使用 ggplot2 中的 geom_roc()
问题描述
我使用以下代码生成 ROC 图
library(plotROC)
library(ggplot2)
library(e1071)
library(mlbench)
data(BreastCancer)
BreastCancer$Class <- ifelse(BreastCancer$Class == "malignant",1,0)
bound <- floor((nrow(BreastCancer)/4)*3)
df <- BreastCancer[sample(nrow(BreastCancer)), ]
training <- df[1:bound,-1]
testing <- df[(bound+1):nrow(df), -1]
nb_mod <- naiveBayes(formula = Class ~ ., data = training)
prob_nb <- predict(nb_mod,testing,type="raw")
df <- data.frame(Class = testing$Class,Prob = prob_nb )
basicplot <- ggplot(df, aes(d = Class, m = Prob.1)) + geom_roc()
我很困惑,因为我在文档 https://cran.r-project.org/web/packages/plotROC/vignettes/examples.html中找到了以下示例:用作美学的标记 M 是大约 -2 之间的值2,不是概率。我是否正确使用了 geom_roc 函数?
library(plotROC)
library(ggplot2)
set.seed(2529)
D.ex <- rbinom(200, size = 1, prob = .5)
M1 <- rnorm(200, mean = D.ex, sd = .65)
M2 <- rnorm(200, mean = D.ex, sd = 1.5)
test <- data.frame(D = D.ex, D.str = c("Healthy", "Ill")[D.ex + 1],
M1 = M1, M2 = M2, stringsAsFactors = FALSE)
basicplot <- ggplot(test, aes(d = D, m = M1)) + geom_roc()
解决方案
转换d
为数字,然后就可以了。
as.numeric(D)
推荐阅读
- javascript - 如何在 React 的不同文件中使用函数?
- google-cloud-platform - 在 Google Spanner 中,是否有可能在已经观察到之后再次出现完全相同的提交时间戳
- swift - 输入数组需要无主?
- javascript - 在 Google Chrome 中使用 MediaStream API 更改 FocusMode 不起作用
- javascript - 使用@UploadFile 上传文件时收到的对象类型
- c++ - -Werror 是否会干扰模板的正确性和/或 SFINAE?
- c# - 如何在dataGridView的行中显示数字
- python - 在 azure blob 存储中重命名 spark 输出 csv
- python-3.x - Python 3 替换 nan 值
- python - WSL: /usr/bin/env: ‘python’: No such file or directory