“Target (y) not found or it is not numeric” -Packa

2019-08-25 02:42发布

I am trying to use smbinning package in R software to find optimal binnings to a certain variable. Running the command

result=smbinning(df=bop,y="FLAG_TARGET",x="VL_TOTL_REND",p=0.05)

returns the following error message:

"Target (y) not found or it is not numeric"

What is happening here? FLAG_TARGET is numeric and I have already tried to change data format to integer but it does not work.

Is there a solution to this issue?

1条回答
Root(大扎)
2楼-- · 2019-08-25 02:48

It is because bop is not a data frame, you have to convert bop into data frame with as.data.frame(bop). If you look at the full smbinning code (https://github.com/cran/smbinning/blob/master/R/smbinning.R#L490), there is this block

i=which(names(df)==y) # Find Column for dependant
j=which(names(df)==x) # Find Column for independant
if (!is.numeric(df[,i]))
{ 
    return("Target (y) not found or it is not numeric")
} 

after setting y as the target column name and x as the predictor column name, try running

i = which(names(bop) == y)
j = which(names(bop) == x)
is.numeric(bop[,i])

if bop is not a dataframe, it will return FALSE. After running bop_dataframe <- as.data.frame(bop) and running

is.numeric(bop_dataframe[,i])

it should return TRUE

查看更多
登录 后发表回答