我在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)发布于 2018-08-05 01:36:52
我改变了roc函数的参数顺序,错误就解决了。
library(pROC)
ROC <- roc( donors$donated, step_prob)
plot(ROC, col = "red")
auc(ROC) https://stackoverflow.com/questions/51578327
复制相似问题