1

我正在尝试在此数据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)

除年龄和目标(已订阅)之外的所有特征都是因子

年龄 - 诠释

已订阅 - 逻辑

4

1 回答 1

0

所有变量都必须是连续的或分类的。如果您将订阅的值从 (T,F) 更改为 (0,1),作为因子变量,它应该可以工作。

我收到此错误是因为我的因子变量值是 (1,2)。在我将它们更改为 (0,1) 后,它对我有用。

于 2020-10-31T22:08:17.540 回答