大家好:
小弟想將每個欄位做自動分箱(woe.binning),但是迴圈一直卡在命名(colnames)的地方,期望是將2~4個欄位剔除5,來做分箱,並合併在一起,以下是我的程式碼,想請問大大們是哪裡寫錯了,感謝
library(dplyr)
library(data.table)
library(naniar)
library(scorecard) # woe IV
library(woeBinning) #自動分箱
library(magrittr)
data(iris)
iris <- mutate(iris,Sepal.Length=ifelse(Sepal.Length>5,1,0))
out = data.frame()
for(i in c(2:4)){
traindata <- data[,c(1,i)]
traindata <- as.data.frame(traindata)
colnames(traindata) <- c("Sepal.Length","x")
traindata <- subset(traindata,x!=5)
traindata$x <- as.numeric(traindata$x)
bins2_tree <- woe.binning(traindata, 'Sepal.Length', traindata)
dataset_woe <- woe.binning.deploy(traindata, bins2_tree, add.woe.or.dum.var = "woe")
out <-dataset_woe[,c(1,3)]
print(i+1)
}