我正在尝试在此数据https://www.kaggle.com/raosuny/success-of-bank-telemarketing-data上构建决策树模型, 并且我正在尝试处理对数据的过采样,但我得到了此错误消息:
Error in data.frame(ynew, Xnew) : object 'ynew' not found
这是我的问题的相关代码:
#Change Target Column to Boolean
levels(subscribe.prep$Subscribed) <- c(FALSE,TRUE)
subscribe.prep$Subscribed <- as.logical(subscribe.prep$Subscribed)
str(subscribe.prep$Subscribed)
#Final df
subscribe <- subscribe.prep
#Decision Tree
filter <- sample.split(subscribe$Subscribed, SplitRatio = 0.7)
subscribe.train <- subset(subscribe, filter == T)
subscribe.test <- subset(subscribe, filter == F)
#Dealing with oversampling
subscribe.train.over <- ovun.sample(Subscribed ~ ., data = subscribe.train, method = 'over', N = 36000)$data
model.dt <- rpart(Subscribed ~ ., subscribe.train.over)
rpart.plot(model.dt, box.palette = "RdBu", shadow.col = "gray", nn = TRUE)
prediciton.dt <- predict(model.dt, subscribe.test, type = "class")
actual.dt <- subscribe.test$Subscribed
confusion_matrix <- table(actual.dt, prediciton.dt > 0.5)
除年龄和目标(已订阅)之外的所有特征都是因子
年龄 - 诠释
已订阅 - 逻辑