Я пытаюсь использовать ROSE, чтобы помочь с несбалансированным набором данных. У меня там около 90%, но у меня проблемы с моим кодом ovun.sample. Когда я запускаю код ovun.sample, он не создает набор данных «поверх», «под» или «оба», значения в R отображаются как NULL (пусто), а не как данные. Буду признателен за любые проблемы со стрельбой, как это можно исправить!
set.seed(123)
ind <- sample(2, nrow(credit), replace = TRUE, prob = c(0.7, 0.3))
train <- credit[ind==1,]
test <- credit[ind==2,]
# Data for Developing the Predictive Model
table(train$DEFAULT)
prop.table(table(train$DEFAULT))
summary(train)
# Sample balancing (Over-, Under-, Both)
library(ROSE)
over <- ovun.sample(DEFAULT~., data = train, method = "over", N = 996)$credit
table(over$DEFAULT)
under <- ovun.sample(DEFAULT~., data = train, method = "under", N = 414)$credit
table(under$DEFAULT)
both <- ovun.sample(DEFAULT~., data = train, method = "both",
p = 0.5, seed = 213, N = 705)$credit
table(both$DEFAULT)
# Predictive Model (Random Forest)
library (randomForest)
rftrain <- randomForest(DEFAULT~., data = train,
ntree = 500, mtry = 10)
rfover <- randomForest(DEFAULT~., data = over,
ntree = 500, mtry = 10)
rfunder <- randomForest(DEFAULT~., data = under,
ntree = 500, mtry = 10)
rfboth <- randomForest(DEFAULT~., data = both,
ntree = 500, mtry = 10)
# Predictive Model Evaluation with test Data
library(caret)
confusionMatrix(predict(rftrain, test), test$DEFAULT, positive = '1')
confusionMatrix(predict(rfover, test), test$DEFAULT, positive = '1')
confusionMatrix(predict(rfunder, test), test$DEFAULT, positive = '1')
confusionMatrix(predict(rfboth, test), test$DEFAULT, positive = '1')```