r - ROC 逐步回归
问题描述
我正在 DataCamp 上使用 R 学习数据科学。在一个练习中,我必须建立一个逐步回归模型。即使我成功创建了逐步模型,roc() 函数也不接受响应,它会给出如下错误:“'response' 有两个以上的级别。考虑明确设置 'levels' 或使用 'multiclass.roc' "
我想学习如何处理这个问题,所以我在下面写了我的代码。
# Specify a null model with no predictors
null_model <- glm(donated ~ 1, data = donors, family = "binomial")
# Specify the full model using all of the potential predictors
full_model <- glm(donated ~ ., data = donors, family = "binomial")
# Use a forward stepwise algorithm to build a parsimonious model
step_model <- step(null_model, scope = list(lower = null_model, upper = full_model), direction = "forward")
# Estimate the stepwise donation probability
step_prob <- predict(step_model, type = "response")
# Plot the ROC of the stepwise model
library(pROC)
ROC <- roc( step_prob, donors$donated)
plot(ROC, col = "red")
auc(ROC)
解决方案
我改变了 roc 函数参数的顺序,错误就解决了。
library(pROC)
ROC <- roc( donors$donated, step_prob)
plot(ROC, col = "red")
auc(ROC)
推荐阅读
- react-native - 是否有禁用标签栏按钮的选项
- c++ - 在不破坏客户端的情况下修复过载
- python-3.x - 无法使用 Bokeh 和 Python 绘制数据点 - 显示空布局
- html - 屏幕阅读器无法阅读整页
- javascript - 如何控制 v-card 的垂直滚动条?
- selenium - chrome 在 dom 中找不到硒的任何元素
- amazon-web-services - 使用 JupyterNotebook 进行 AWS Congito 身份验证
- pandas - 使用 pandas 运行分析报告时出错,给我一个错误“TypeError: describe_boolean_1d() got an unexpected keyword argument 'title'”
- python - 在父级之外绘制 QGraphicsWidget
- r - Mac上的R Gui应用程序在调用历史记录时添加空行