More on wind control modeling, big data analysis and other content please pay attention to the public number "big data wind control bit by bit"
After splitting the variables, it is important to calculate the importance of the variables, and IV is one of the statistics that evaluates the sensitivity or importance of the variable, and the code for the R language calculates the IV value as follows:
CalcIV <- function(df_bin, key_var, y_var){ N_0<-table(df_bin[, y_var])[1] N_1<-table(df_bin[, y_var])[2] iv_c<-NULL var_c<-NULL for (col in colnames(df_bin)){ if (col != key_var && col != y_var) { frq<-as.data.frame(table(df_bin[, col], df_bin[, y_var])) len<-length(unique(frq$Var1)) iv<-0 for (i in 1:len){ N_i_0<-frq$Freq[frq$Var1==i & frq$Var2==0] N_i_1<-frq$Freq[frq$Var1==i & frq$Var2==1] iv<-iv+(N_i_0/N_0- N_i_1/N_1)*log((N_i_0/N_0)/(N_i_1/N_1)) } iv_c<-c(iv_c, iv) var_c<-c(var_c, col) } } iv_df<-data.frame(var=var_c, iv=iv_c, stringsAsFactors = FALSE) return(iv_df)}
Where Df_bin is the data set after the bins, Key_var is the primary key, Y_var is the y variable (0 is good, 1 is bad). The result of the code operation is as follows:
R Language Computing IV value and its use