“Target (y) not found or it is not numeric” -Package smbinning - R

核能气质少年 提交于 2019-12-25 16:09:23

问题


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:


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



来源:https://stackoverflow.com/questions/45461816/target-y-not-found-or-it-is-not-numeric-package-smbinning-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!