suppressMessages(library(PDtoolkit))
data(loans)
#check numeric variables (note that one of variables is target not a risk factor)
names(loans)[sapply(loans, is.numeric)]
#define constains of numeric risk factors
num.rf.const <- data.frame(rf = c("Duration of Credit (month)", "Credit Amount", "Age (years)"),
lower = c(4, 250, 19),
upper = c(72, 20000, 75),
type = c("integer", "numeric", "integer"))
num.rf.const
#loans$"Account Balance"[990:1000] <- NA
#loans$"Credit Amount"[900:920] <- NA
loans.s <- smote(db = loans,
target = "Creditability",
minority.class = 1,
osr = 0.05,
ordinal.rf = NULL,
num.rf.const = num.rf.const,
k = 5,
seed = 81000)
str(loans.s)
table(loans.s$Creditability, loans.s$smote)
#select minority class
loans.mc <- loans.s[loans.s$Creditability%in%1, ]
head(loans.mc)
Run the code above in your browser using DataLab