ROSE:data.frame(ynew, Xnew) 中的错误:未找到对象 'ynew'
ROSE : Error in data.frame(ynew, Xnew) : object 'ynew' not found
我正在尝试基于此数据构建决策树模型 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)
除了年龄和目标(已订阅)之外的所有特征都是因子
年龄 - 智力
已订阅 - 逻辑
所有变量都必须是连续的或分类的。如果您将 Subscribed 的值从 (T,F) 更改为 (0,1),作为因子变量,它应该有效。
我收到此错误是因为我的因子变量值是 (1,2)。在我将它们更改为 (0,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)
除了年龄和目标(已订阅)之外的所有特征都是因子
年龄 - 智力
已订阅 - 逻辑
所有变量都必须是连续的或分类的。如果您将 Subscribed 的值从 (T,F) 更改为 (0,1),作为因子变量,它应该有效。
我收到此错误是因为我的因子变量值是 (1,2)。在我将它们更改为 (0,1) 后,它对我有用。