我在为 rpart 包创建的决策树创建 ROC 曲线时遇到问题。我的目标是预测“y”银行营销活动的成功。最后,您可以得到“是”或“否”作为可能的答案。我怎样才能接近我的下一步 ROC 曲线图?
这是我到目前为止的R代码:
library(caTools)
library(rpart)
library(rpart.plot)
set.seed(1234)
sample = sample.split(bank$y, SplitRatio = .75)
train = subset(bank, sample==TRUE)
test = subset(bank, sample==FALSE)
tree <-rpart(y ~.,method="class",data=train)
tree.preds<-predict(tree, test)
tree.preds<-as.data.frame(tree.preds)
joiner <- function(x) {if (x >= 0.5) {return("Yes") } else {return("No")}}
tree.preds$y <- sapply(tree.preds$yes, joiner)
table(tree.preds$y, test$y)
prp(tree)