APRENDIZAJE SUPERVISADO

1. Etapa 1: Entendimiento de los datos

Bases de Datos (Estructurada)

library(readxl)
DatosCopiaExp <- read_excel("D:/01_PUJ/00_Trabajo_de_grado/Data/DatosBD27052023.xlsx")

datos <-  as.data.frame(DatosCopiaExp)
datos$Default=as.factor(datos$Default)

attach(datos)
head(datos)

Convertimos la variable Default en factor.

datos$Default <- factor(datos$Default)

Tratamiento NA

colSums(is.na(datos))
##                          Edad                       Estrato 
##                             0                             0 
##              Personas a Cargo            Tiemp_Vinc_Lab_Mes 
##                             0                             0 
##                Ingreso_Basico                Aux_Transporte 
##                             0                             0 
##                Otros_Ingresos       Base_70_Ingr_consti_Sal 
##                             0                             0 
##                    Ded_Nomina                 Tot_Gast_Fami 
##                             0                             0 
##         Cuot_Men_Tdc_Cred_Rot         Cuot_Mens_Otras_Oblig 
##                             0                             0 
##                      Sal_Disp                Sal_Obli_Exter 
##                             0                             0 
##           Sal_Obli_Ded_Nomina              Sal_Créd_Viv_Veh 
##                             0                             0 
##              Sal_TDC_Cred_Rot                  Punt_Acierta 
##                             0                             0 
##                  Tot_Cuot_Pag Porc_Proy_Liquid_Resp_Credito 
##                             0                             0 
##                  Porc_Ded_Nom                 Porc_Cap_Pago 
##                             0                             0 
##                Porc_Gast_Fina          End_Max_ Vec_Salario 
##                             0                             0 
##                  Mont_Credito                     Plazo_OPA 
##                             0                             0 
##                      CateAfil                         sexo2 
##                             0                             0 
##                     EstaCivil                    ConyLabora 
##                             0                             0 
##                  TipoVivienda                     NivelEduc 
##                             0                             0 
##                  TipoContrato            CumpleTiempoVincul 
##                             0                             0 
##                   MoraObliVig                       Default 
##                             0                             0
str(datos)
## 'data.frame':    15813 obs. of  36 variables:
##  $ Edad                         : num  40 57 31 52 33 53 29 41 23 43 ...
##  $ Estrato                      : num  3 2 3 2 2 1 3 3 3 1 ...
##  $ Personas a Cargo             : num  2 0 0 1 1 1 3 1 0 3 ...
##  $ Tiemp_Vinc_Lab_Mes           : num  23 57.5 26.3 143.6 11.4 ...
##  $ Ingreso_Basico               : num  737717 750000 1595984 2311221 737717 ...
##  $ Aux_Transporte               : num  83140 83140 0 0 83140 ...
##  $ Otros_Ingresos               : num  158200 0 0 0 0 ...
##  $ Base_70_Ingr_consti_Sal      : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Ded_Nomina                   : num  59018 60000 129603 830024 120569 ...
##  $ Tot_Gast_Fami                : num  293717 249942 478795 693366 246257 ...
##  $ Cuot_Men_Tdc_Cred_Rot        : num  0 0 0 25254 0 ...
##  $ Cuot_Mens_Otras_Oblig        : num  0 0 0 0 0 181000 0 0 67000 60000 ...
##  $ Sal_Disp                     : num  626322 523198 987586 762577 454031 ...
##  $ Sal_Obli_Exter               : num  0 0 0 5131006 0 ...
##  $ Sal_Obli_Ded_Nomina          : num  0 0 0 24638000 0 ...
##  $ Sal_Créd_Viv_Veh             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ Sal_TDC_Cred_Rot             : num  0 0 0 467000 0 0 0 0 0 0 ...
##  $ Punt_Acierta                 : num  683 803 838 665 794 694 424 705 727 556 ...
##  $ Tot_Cuot_Pag                 : num  96516 72842 107736 116714 100158 ...
##  $ Porc_Proy_Liquid_Resp_Credito: num  1.121 3.309 0.954 0 0.671 ...
##  $ Porc_Ded_Nom                 : num  0.211 0.177 0.149 0.41 0.299 ...
##  $ Porc_Cap_Pago                : num  0.459 0.459 0.449 0.721 0.569 ...
##  $ Porc_Gast_Fina               : num  0.1049 0.0942 0.0735 0.0958 0.143 ...
##  $ End_Max_ Vec_Salario         : num  1.08 0.96 1.88 14.29 1.34 ...
##  $ Mont_Credito                 : num  1060000 800000 3000000 3250000 1100000 ...
##  $ Plazo_OPA                    : num  12 12 36 36 12 12 12 15 18 18 ...
##  $ CateAfil                     : num  1 1 3 3 1 2 2 1 2 2 ...
##  $ sexo2                        : num  1 1 1 0 0 0 1 1 1 1 ...
##  $ EstaCivil                    : num  3 2 3 1 1 1 3 1 1 3 ...
##  $ ConyLabora                   : num  1 1 1 1 1 1 2 1 1 2 ...
##  $ TipoVivienda                 : num  2 3 1 3 1 2 3 1 2 2 ...
##  $ NivelEduc                    : num  2 2 3 5 2 1 2 2 3 2 ...
##  $ TipoContrato                 : num  7 7 7 7 7 7 2 7 7 7 ...
##  $ CumpleTiempoVincul           : num  2 2 2 2 2 2 2 2 2 2 ...
##  $ MoraObliVig                  : num  6 15 15 15 15 15 10 15 15 15 ...
##  $ Default                      : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 2 1 2 ...
library(skimr)
skimr::skim(datos)
Data summary
Name datos
Number of rows 15813
Number of columns 36
_______________________
Column type frequency:
factor 1
numeric 35
________________________
Group variables None

Variable type: factor

skim_variable n_missing complete_rate ordered n_unique top_counts
Default 0 1 FALSE 2 0: 15190, 1: 623

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
Edad 0 1 35.72 1.060000e+01 18.00 27.00 34.00 43.00 6.900000e+01 ▇▇▅▃▁
Estrato 0 1 2.29 8.800000e-01 1.00 2.00 2.00 3.00 6.000000e+00 ▇▅▁▁▁
Personas a Cargo 0 1 1.18 1.130000e+00 0.00 0.00 1.00 2.00 1.000000e+01 ▇▁▁▁▁
Tiemp_Vinc_Lab_Mes 0 1 60.74 6.933000e+01 0.03 16.97 34.80 73.87 4.771700e+02 ▇▁▁▁▁
Ingreso_Basico 0 1 1294322.86 9.401741e+05 737717.00 828116.00 953614.00 1418970.00 2.544700e+07 ▇▁▁▁▁
Aux_Transporte 0 1 71771.77 4.112031e+04 0.00 83140.00 88211.00 97032.00 1.028540e+05 ▂▁▁▁▇
Otros_Ingresos 0 1 47443.51 3.970631e+05 0.00 0.00 0.00 0.00 1.933709e+07 ▇▁▁▁▁
Base_70_Ingr_consti_Sal 0 1 96509.35 3.020664e+05 0.00 0.00 0.00 0.00 7.059080e+06 ▇▁▁▁▁
Ded_Nomina 0 1 202413.09 3.140426e+05 0.00 76827.00 121474.16 221600.00 1.148501e+07 ▇▁▁▁▁
Tot_Gast_Fami 0 1 382546.43 2.831822e+05 110657.55 260835.90 315983.40 428592.00 9.028440e+06 ▇▁▁▁▁
Cuot_Men_Tdc_Cred_Rot 0 1 15317.63 8.260993e+04 0.00 0.00 0.00 0.00 3.892214e+06 ▇▁▁▁▁
Cuot_Mens_Otras_Oblig 0 1 143032.63 3.406665e+05 0.00 0.00 63000.00 181000.00 1.338300e+07 ▇▁▁▁▁
Sal_Disp 0 1 737800.60 4.646815e+05 -5283079.07 507679.10 628977.78 845198.00 1.697228e+07 ▁▇▁▁▁
Sal_Obli_Exter 0 1 2156011.86 7.630374e+06 0.00 0.00 420000.00 1855000.00 3.234400e+08 ▇▁▁▁▁
Sal_Obli_Ded_Nomina 0 1 501701.46 3.761631e+06 0.00 0.00 0.00 0.00 1.194650e+08 ▇▁▁▁▁
Sal_Créd_Viv_Veh 0 1 12059185.81 1.298581e+09 0.00 0.00 0.00 0.00 1.632890e+11 ▇▁▁▁▁
Sal_TDC_Cred_Rot 0 1 234124.38 1.280756e+06 0.00 0.00 0.00 0.00 5.733900e+07 ▇▁▁▁▁
Punt_Acierta 0 1 683.64 1.862700e+02 0.00 667.00 727.00 781.00 9.380000e+02 ▁▁▁▇▆
Tot_Cuot_Pag 0 1 174075.56 1.176718e+05 9663.16 108106.23 136874.08 190717.41 1.637944e+06 ▇▁▁▁▁
Porc_Proy_Liquid_Resp_Credito 0 1 1.25 2.000000e+00 0.00 0.50 0.73 1.30 5.725000e+01 ▇▁▁▁▁
Porc_Ded_Nom 0 1 0.27 9.000000e-02 0.06 0.20 0.25 0.33 1.160000e+00 ▇▅▁▁▁
Porc_Cap_Pago 0 1 0.60 1.400000e-01 0.18 0.50 0.59 0.70 2.610000e+00 ▇▃▁▁▁
Porc_Gast_Fina 0 1 0.23 1.200000e-01 0.01 0.14 0.21 0.31 2.430000e+00 ▇▁▁▁▁
End_Max_ Vec_Salario 0 1 4.41 3.160000e+00 0.21 2.14 3.57 5.90 3.981000e+01 ▇▁▁▁▁
Mont_Credito 0 1 4560092.87 4.782340e+06 340000.00 1700000.00 3053000.00 5346000.00 5.382754e+07 ▇▁▁▁▁
Plazo_OPA 0 1 29.73 1.659000e+01 3.00 18.00 24.00 36.00 9.600000e+01 ▇▇▂▃▁
CateAfil 0 1 1.98 7.400000e-01 1.00 2.00 2.00 2.00 4.000000e+00 ▃▇▁▂▁
sexo2 0 1 0.58 4.900000e-01 0.00 0.00 1.00 1.00 1.000000e+00 ▆▁▁▁▇
EstaCivil 0 1 1.84 9.700000e-01 1.00 1.00 1.00 3.00 5.000000e+00 ▇▃▃▁▁
ConyLabora 0 1 1.26 4.400000e-01 1.00 1.00 1.00 2.00 2.000000e+00 ▇▁▁▁▃
TipoVivienda 0 1 2.11 6.400000e-01 1.00 2.00 2.00 3.00 3.000000e+00 ▂▁▇▁▃
NivelEduc 0 1 2.86 1.310000e+00 1.00 2.00 2.00 4.00 6.000000e+00 ▇▃▂▂▁
TipoContrato 0 1 5.32 2.450000e+00 1.00 2.00 7.00 7.00 7.000000e+00 ▃▁▁▁▇
CumpleTiempoVincul 0 1 1.94 2.300000e-01 1.00 2.00 2.00 2.00 2.000000e+00 ▁▁▁▁▇
MoraObliVig 0 1 14.23 2.360000e+00 1.00 15.00 15.00 15.00 1.500000e+01 ▁▁▁▁▇
table(datos$Default)
## 
##     0     1 
## 15190   623
prop.table(table(datos$Default))
## 
##          0          1 
## 0.96060204 0.03939796

2. Etapa 2: Preparación de los datos

La variable Default se cambia a factor

2.1. Modelo Logit sin reducción de dimensionalidad ni balanceo de datos

datos$Default=as.factor(datos$Default)
mod=glm(Default~.,data=datos,family = "binomial")
mod
## 
## Call:  glm(formula = Default ~ ., family = "binomial", data = datos)
## 
## Coefficients:
##                   (Intercept)                           Edad  
##                     2.322e+00                     -1.520e-02  
##                       Estrato             `Personas a Cargo`  
##                    -3.197e-02                     -1.494e-02  
##            Tiemp_Vinc_Lab_Mes                 Ingreso_Basico  
##                     9.795e-04                      6.057e-01  
##                Aux_Transporte                 Otros_Ingresos  
##                     6.057e-01                      6.057e-01  
##       Base_70_Ingr_consti_Sal                     Ded_Nomina  
##                     4.240e-01                     -6.057e-01  
##                 Tot_Gast_Fami          Cuot_Men_Tdc_Cred_Rot  
##                    -6.057e-01                     -6.058e-01  
##         Cuot_Mens_Otras_Oblig                       Sal_Disp  
##                    -6.057e-01                     -6.057e-01  
##                Sal_Obli_Exter            Sal_Obli_Ded_Nomina  
##                     7.789e-09                     -2.180e-08  
##              Sal_Créd_Viv_Veh               Sal_TDC_Cred_Rot  
##                    -5.111e-09                      5.615e-07  
##                  Punt_Acierta                   Tot_Cuot_Pag  
##                    -4.705e-04                     -7.474e-06  
## Porc_Proy_Liquid_Resp_Credito                   Porc_Ded_Nom  
##                    -4.830e-01                      3.313e+00  
##                 Porc_Cap_Pago                 Porc_Gast_Fina  
##                    -5.469e+00                      6.156e+00  
##        `End_Max_ Vec_Salario`                   Mont_Credito  
##                    -4.696e-02                      9.447e-08  
##                     Plazo_OPA                       CateAfil  
##                    -4.304e-03                     -3.283e-01  
##                         sexo2                      EstaCivil  
##                     3.032e-01                      2.909e-04  
##                    ConyLabora                   TipoVivienda  
##                    -8.615e-01                     -6.178e-02  
##                     NivelEduc                   TipoContrato  
##                    -1.263e-01                     -5.824e-02  
##            CumpleTiempoVincul                    MoraObliVig  
##                     1.970e-01                     -3.150e-02  
## 
## Degrees of Freedom: 15812 Total (i.e. Null);  15777 Residual
## Null Deviance:       5251 
## Residual Deviance: 4964  AIC: 5036
summary(mod)
## 
## Call:
## glm(formula = Default ~ ., family = "binomial", data = datos)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.1716  -0.3235  -0.2598  -0.1931   3.7527  
## 
## Coefficients:
##                                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    2.322e+00  1.013e+00   2.293 0.021871 *  
## Edad                          -1.520e-02  5.013e-03  -3.033 0.002423 ** 
## Estrato                       -3.197e-02  5.694e-02  -0.561 0.574556    
## `Personas a Cargo`            -1.494e-02  4.105e-02  -0.364 0.715945    
## Tiemp_Vinc_Lab_Mes             9.795e-04  1.763e-03   0.556 0.578506    
## Ingreso_Basico                 6.057e-01  8.035e-01   0.754 0.450905    
## Aux_Transporte                 6.057e-01  8.035e-01   0.754 0.450908    
## Otros_Ingresos                 6.057e-01  8.035e-01   0.754 0.450906    
## Base_70_Ingr_consti_Sal        4.240e-01  5.624e-01   0.754 0.450906    
## Ded_Nomina                    -6.057e-01  8.035e-01  -0.754 0.450906    
## Tot_Gast_Fami                 -6.057e-01  8.035e-01  -0.754 0.450906    
## Cuot_Men_Tdc_Cred_Rot         -6.058e-01  8.035e-01  -0.754 0.450899    
## Cuot_Mens_Otras_Oblig         -6.057e-01  8.035e-01  -0.754 0.450906    
## Sal_Disp                      -6.057e-01  8.035e-01  -0.754 0.450906    
## Sal_Obli_Exter                 7.789e-09  1.416e-08   0.550 0.582161    
## Sal_Obli_Ded_Nomina           -2.180e-08  2.752e-08  -0.792 0.428158    
## Sal_Créd_Viv_Veh              -5.111e-09  6.326e-09  -0.808 0.419144    
## Sal_TDC_Cred_Rot               5.615e-07  3.872e-07   1.450 0.147036    
## Punt_Acierta                  -4.705e-04  2.005e-04  -2.347 0.018947 *  
## Tot_Cuot_Pag                  -7.474e-06  1.972e-06  -3.790 0.000151 ***
## Porc_Proy_Liquid_Resp_Credito -4.830e-01  1.075e-01  -4.494 6.99e-06 ***
## Porc_Ded_Nom                   3.313e+00  1.537e+00   2.155 0.031167 *  
## Porc_Cap_Pago                 -5.469e+00  1.938e+00  -2.822 0.004776 ** 
## Porc_Gast_Fina                 6.156e+00  1.937e+00   3.177 0.001487 ** 
## `End_Max_ Vec_Salario`        -4.696e-02  3.642e-02  -1.290 0.197204    
## Mont_Credito                   9.448e-08  4.325e-08   2.185 0.028917 *  
## Plazo_OPA                     -4.304e-03  6.321e-03  -0.681 0.495943    
## CateAfil                      -3.283e-01  1.043e-01  -3.149 0.001640 ** 
## sexo2                          3.032e-01  9.266e-02   3.273 0.001065 ** 
## EstaCivil                      2.909e-04  5.311e-02   0.005 0.995630    
## ConyLabora                    -8.615e-01  3.357e-01  -2.566 0.010287 *  
## TipoVivienda                  -6.178e-02  6.868e-02  -0.900 0.368369    
## NivelEduc                     -1.263e-01  4.752e-02  -2.658 0.007868 ** 
## TipoContrato                  -5.824e-02  1.720e-02  -3.385 0.000711 ***
## CumpleTiempoVincul             1.970e-01  1.655e-01   1.191 0.233768    
## MoraObliVig                   -3.150e-02  1.699e-02  -1.853 0.063828 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 5250.7  on 15812  degrees of freedom
## Residual deviance: 4964.3  on 15777  degrees of freedom
## AIC: 5036.3
## 
## Number of Fisher Scoring iterations: 17

Se obtiene unas pocas variables con significancia.

2.2. Usando Setp para reduccion de dimensionalidad

La reducción de dimensionalidad se encarga de identificar y eliminar las características que disminuyen el rendimiento del modelo de aprendizaje automático.

mod_2=step(mod)
## Start:  AIC=5036.27
## Default ~ Edad + Estrato + `Personas a Cargo` + Tiemp_Vinc_Lab_Mes + 
##     Ingreso_Basico + Aux_Transporte + Otros_Ingresos + Base_70_Ingr_consti_Sal + 
##     Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Sal_Obli_Exter + Sal_Obli_Ded_Nomina + Sal_Créd_Viv_Veh + 
##     Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + Plazo_OPA + CateAfil + sexo2 + EstaCivil + 
##     ConyLabora + TipoVivienda + NivelEduc + TipoContrato + CumpleTiempoVincul + 
##     MoraObliVig
## 
##                                 Df Deviance    AIC
## - EstaCivil                      1   4964.3 5034.3
## - `Personas a Cargo`             1   4964.4 5034.4
## - Sal_Obli_Exter                 1   4964.6 5034.6
## - Tiemp_Vinc_Lab_Mes             1   4964.6 5034.6
## - Estrato                        1   4964.6 5034.6
## - Plazo_OPA                      1   4964.7 5034.7
## - Sal_Obli_Ded_Nomina            1   4965.0 5035.0
## - Sal_Créd_Viv_Veh               1   4965.1 5035.1
## - TipoVivienda                   1   4965.1 5035.1
## - Aux_Transporte                 1   4965.2 5035.2
## - Base_70_Ingr_consti_Sal        1   4965.2 5035.2
## - Cuot_Mens_Otras_Oblig          1   4965.3 5035.3
## - Otros_Ingresos                 1   4965.3 5035.3
## - Sal_Disp                       1   4965.3 5035.3
## - Tot_Gast_Fami                  1   4965.3 5035.3
## - Ded_Nomina                     1   4965.3 5035.3
## - Ingreso_Basico                 1   4965.3 5035.3
## - Cuot_Men_Tdc_Cred_Rot          1   4965.5 5035.5
## - CumpleTiempoVincul             1   4965.7 5035.7
## - `End_Max_ Vec_Salario`         1   4966.0 5036.0
## - Sal_TDC_Cred_Rot               1   4966.2 5036.2
## <none>                               4964.3 5036.3
## - MoraObliVig                    1   4967.5 5037.5
## - Mont_Credito                   1   4968.8 5038.8
## - Porc_Ded_Nom                   1   4968.8 5038.8
## - Punt_Acierta                   1   4969.5 5039.5
## - ConyLabora                     1   4970.9 5040.9
## - NivelEduc                      1   4971.5 5041.5
## - Porc_Cap_Pago                  1   4972.2 5042.2
## - Edad                           1   4973.8 5043.8
## - CateAfil                       1   4974.2 5044.2
## - Porc_Gast_Fina                 1   4974.2 5044.2
## - sexo2                          1   4975.2 5045.2
## - TipoContrato                   1   4975.5 5045.5
## - Tot_Cuot_Pag                   1   4979.1 5049.1
## - Porc_Proy_Liquid_Resp_Credito  1   4990.9 5060.9
## 
## Step:  AIC=5034.27
## Default ~ Edad + Estrato + `Personas a Cargo` + Tiemp_Vinc_Lab_Mes + 
##     Ingreso_Basico + Aux_Transporte + Otros_Ingresos + Base_70_Ingr_consti_Sal + 
##     Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Sal_Obli_Exter + Sal_Obli_Ded_Nomina + Sal_Créd_Viv_Veh + 
##     Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + Plazo_OPA + CateAfil + sexo2 + ConyLabora + 
##     TipoVivienda + NivelEduc + TipoContrato + CumpleTiempoVincul + 
##     MoraObliVig
## 
##                                 Df Deviance    AIC
## - `Personas a Cargo`             1   4964.4 5032.4
## - Sal_Obli_Exter                 1   4964.6 5032.6
## - Tiemp_Vinc_Lab_Mes             1   4964.6 5032.6
## - Estrato                        1   4964.6 5032.6
## - Plazo_OPA                      1   4964.7 5032.7
## - Sal_Obli_Ded_Nomina            1   4965.0 5033.0
## - Sal_Créd_Viv_Veh               1   4965.1 5033.1
## - TipoVivienda                   1   4965.1 5033.1
## - Aux_Transporte                 1   4965.2 5033.2
## - Base_70_Ingr_consti_Sal        1   4965.2 5033.2
## - Cuot_Mens_Otras_Oblig          1   4965.3 5033.3
## - Otros_Ingresos                 1   4965.3 5033.3
## - Sal_Disp                       1   4965.3 5033.3
## - Tot_Gast_Fami                  1   4965.3 5033.3
## - Ded_Nomina                     1   4965.3 5033.3
## - Ingreso_Basico                 1   4965.3 5033.3
## - Cuot_Men_Tdc_Cred_Rot          1   4965.5 5033.5
## - CumpleTiempoVincul             1   4965.7 5033.7
## - `End_Max_ Vec_Salario`         1   4966.0 5034.0
## - Sal_TDC_Cred_Rot               1   4966.2 5034.2
## <none>                               4964.3 5034.3
## - MoraObliVig                    1   4967.5 5035.5
## - Mont_Credito                   1   4968.8 5036.8
## - Porc_Ded_Nom                   1   4968.8 5036.8
## - Punt_Acierta                   1   4969.5 5037.5
## - ConyLabora                     1   4971.2 5039.2
## - NivelEduc                      1   4971.5 5039.5
## - Porc_Cap_Pago                  1   4972.2 5040.2
## - Edad                           1   4974.0 5042.0
## - CateAfil                       1   4974.2 5042.2
## - Porc_Gast_Fina                 1   4974.2 5042.2
## - sexo2                          1   4975.2 5043.2
## - TipoContrato                   1   4975.5 5043.5
## - Tot_Cuot_Pag                   1   4979.1 5047.1
## - Porc_Proy_Liquid_Resp_Credito  1   4990.9 5058.9
## 
## Step:  AIC=5032.41
## Default ~ Edad + Estrato + Tiemp_Vinc_Lab_Mes + Ingreso_Basico + 
##     Aux_Transporte + Otros_Ingresos + Base_70_Ingr_consti_Sal + 
##     Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Sal_Obli_Exter + Sal_Obli_Ded_Nomina + Sal_Créd_Viv_Veh + 
##     Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + Plazo_OPA + CateAfil + sexo2 + ConyLabora + 
##     TipoVivienda + NivelEduc + TipoContrato + CumpleTiempoVincul + 
##     MoraObliVig
## 
##                                 Df Deviance    AIC
## - Estrato                        1   4964.7 5030.7
## - Sal_Obli_Exter                 1   4964.7 5030.7
## - Tiemp_Vinc_Lab_Mes             1   4964.7 5030.7
## - Plazo_OPA                      1   4964.9 5030.9
## - Sal_Obli_Ded_Nomina            1   4965.1 5031.1
## - TipoVivienda                   1   4965.2 5031.2
## - Sal_Créd_Viv_Veh               1   4965.2 5031.2
## - Aux_Transporte                 1   4965.3 5031.3
## - Base_70_Ingr_consti_Sal        1   4965.4 5031.4
## - Cuot_Mens_Otras_Oblig          1   4965.4 5031.4
## - Otros_Ingresos                 1   4965.4 5031.4
## - Sal_Disp                       1   4965.4 5031.4
## - Tot_Gast_Fami                  1   4965.4 5031.4
## - Ded_Nomina                     1   4965.4 5031.4
## - Ingreso_Basico                 1   4965.4 5031.4
## - Cuot_Men_Tdc_Cred_Rot          1   4965.6 5031.6
## - CumpleTiempoVincul             1   4965.9 5031.9
## - `End_Max_ Vec_Salario`         1   4966.1 5032.1
## - Sal_TDC_Cred_Rot               1   4966.4 5032.4
## <none>                               4964.4 5032.4
## - MoraObliVig                    1   4967.6 5033.6
## - Mont_Credito                   1   4968.9 5034.9
## - Porc_Ded_Nom                   1   4969.0 5035.0
## - Punt_Acierta                   1   4969.7 5035.7
## - ConyLabora                     1   4971.4 5037.4
## - NivelEduc                      1   4971.5 5037.5
## - Porc_Cap_Pago                  1   4972.4 5038.4
## - CateAfil                       1   4974.3 5040.3
## - Porc_Gast_Fina                 1   4974.4 5040.4
## - Edad                           1   4975.2 5041.2
## - sexo2                          1   4975.2 5041.2
## - TipoContrato                   1   4975.6 5041.6
## - Tot_Cuot_Pag                   1   4979.3 5045.3
## - Porc_Proy_Liquid_Resp_Credito  1   4991.2 5057.2
## 
## Step:  AIC=5030.67
## Default ~ Edad + Tiemp_Vinc_Lab_Mes + Ingreso_Basico + Aux_Transporte + 
##     Otros_Ingresos + Base_70_Ingr_consti_Sal + Ded_Nomina + Tot_Gast_Fami + 
##     Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + Sal_Disp + 
##     Sal_Obli_Exter + Sal_Obli_Ded_Nomina + Sal_Créd_Viv_Veh + 
##     Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + Plazo_OPA + CateAfil + sexo2 + ConyLabora + 
##     TipoVivienda + NivelEduc + TipoContrato + CumpleTiempoVincul + 
##     MoraObliVig
## 
##                                 Df Deviance    AIC
## - Sal_Obli_Exter                 1   4964.9 5028.9
## - Tiemp_Vinc_Lab_Mes             1   4965.0 5029.0
## - Plazo_OPA                      1   4965.1 5029.1
## - Sal_Obli_Ded_Nomina            1   4965.4 5029.4
## - TipoVivienda                   1   4965.4 5029.4
## - Sal_Créd_Viv_Veh               1   4965.5 5029.5
## - Aux_Transporte                 1   4965.6 5029.6
## - Base_70_Ingr_consti_Sal        1   4965.6 5029.6
## - Cuot_Mens_Otras_Oblig          1   4965.7 5029.7
## - Otros_Ingresos                 1   4965.7 5029.7
## - Tot_Gast_Fami                  1   4965.7 5029.7
## - Sal_Disp                       1   4965.7 5029.7
## - Ded_Nomina                     1   4965.7 5029.7
## - Ingreso_Basico                 1   4965.7 5029.7
## - Cuot_Men_Tdc_Cred_Rot          1   4965.9 5029.9
## - CumpleTiempoVincul             1   4966.1 5030.1
## - `End_Max_ Vec_Salario`         1   4966.3 5030.3
## - Sal_TDC_Cred_Rot               1   4966.6 5030.6
## <none>                               4964.7 5030.7
## - MoraObliVig                    1   4967.8 5031.8
## - Mont_Credito                   1   4969.1 5033.1
## - Porc_Ded_Nom                   1   4969.2 5033.2
## - Punt_Acierta                   1   4970.0 5034.0
## - ConyLabora                     1   4971.6 5035.6
## - Porc_Cap_Pago                  1   4972.5 5036.5
## - NivelEduc                      1   4972.9 5036.9
## - Porc_Gast_Fina                 1   4974.5 5038.5
## - CateAfil                       1   4974.8 5038.8
## - sexo2                          1   4975.6 5039.6
## - Edad                           1   4975.9 5039.9
## - TipoContrato                   1   4975.9 5039.9
## - Tot_Cuot_Pag                   1   4979.5 5043.5
## - Porc_Proy_Liquid_Resp_Credito  1   4991.5 5055.5
## 
## Step:  AIC=5028.95
## Default ~ Edad + Tiemp_Vinc_Lab_Mes + Ingreso_Basico + Aux_Transporte + 
##     Otros_Ingresos + Base_70_Ingr_consti_Sal + Ded_Nomina + Tot_Gast_Fami + 
##     Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + Sal_Disp + 
##     Sal_Obli_Ded_Nomina + Sal_Créd_Viv_Veh + Sal_TDC_Cred_Rot + 
##     Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + Plazo_OPA + CateAfil + sexo2 + ConyLabora + 
##     TipoVivienda + NivelEduc + TipoContrato + CumpleTiempoVincul + 
##     MoraObliVig
## 
##                                 Df Deviance    AIC
## - Tiemp_Vinc_Lab_Mes             1   4965.2 5027.2
## - Plazo_OPA                      1   4965.6 5027.6
## - TipoVivienda                   1   4965.7 5027.7
## - Aux_Transporte                 1   4965.9 5027.9
## - Base_70_Ingr_consti_Sal        1   4965.9 5027.9
## - Cuot_Mens_Otras_Oblig          1   4965.9 5027.9
## - Tot_Gast_Fami                  1   4965.9 5027.9
## - Otros_Ingresos                 1   4965.9 5027.9
## - Sal_Disp                       1   4965.9 5027.9
## - Ded_Nomina                     1   4965.9 5027.9
## - Ingreso_Basico                 1   4965.9 5027.9
## - Sal_Obli_Ded_Nomina            1   4966.1 5028.1
## - Cuot_Men_Tdc_Cred_Rot          1   4966.1 5028.1
## - Sal_Créd_Viv_Veh               1   4966.3 5028.3
## - `End_Max_ Vec_Salario`         1   4966.4 5028.4
## - CumpleTiempoVincul             1   4966.4 5028.4
## - Sal_TDC_Cred_Rot               1   4966.8 5028.8
## <none>                               4964.9 5028.9
## - MoraObliVig                    1   4968.1 5030.1
## - Porc_Ded_Nom                   1   4969.3 5031.3
## - Mont_Credito                   1   4969.3 5031.3
## - Punt_Acierta                   1   4970.3 5032.3
## - ConyLabora                     1   4971.7 5033.7
## - Porc_Cap_Pago                  1   4972.8 5034.8
## - NivelEduc                      1   4973.2 5035.2
## - Porc_Gast_Fina                 1   4974.5 5036.5
## - CateAfil                       1   4975.1 5037.1
## - sexo2                          1   4975.9 5037.9
## - TipoContrato                   1   4976.2 5038.2
## - Edad                           1   4976.2 5038.2
## - Tot_Cuot_Pag                   1   4979.5 5041.5
## - Porc_Proy_Liquid_Resp_Credito  1   4991.5 5053.5
## 
## Step:  AIC=5027.22
## Default ~ Edad + Ingreso_Basico + Aux_Transporte + Otros_Ingresos + 
##     Base_70_Ingr_consti_Sal + Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + 
##     Cuot_Mens_Otras_Oblig + Sal_Disp + Sal_Obli_Ded_Nomina + 
##     Sal_Créd_Viv_Veh + Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + 
##     Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + Porc_Cap_Pago + 
##     Porc_Gast_Fina + `End_Max_ Vec_Salario` + Mont_Credito + 
##     Plazo_OPA + CateAfil + sexo2 + ConyLabora + TipoVivienda + 
##     NivelEduc + TipoContrato + CumpleTiempoVincul + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Plazo_OPA                      1   4965.7 5025.7
## - TipoVivienda                   1   4965.9 5025.9
## - Sal_Obli_Ded_Nomina            1   4966.1 5026.1
## - Aux_Transporte                 1   4966.2 5026.2
## - Base_70_Ingr_consti_Sal        1   4966.2 5026.2
## - Cuot_Mens_Otras_Oblig          1   4966.2 5026.2
## - Tot_Gast_Fami                  1   4966.2 5026.2
## - Otros_Ingresos                 1   4966.2 5026.2
## - Sal_Disp                       1   4966.2 5026.2
## - Ded_Nomina                     1   4966.2 5026.2
## - Ingreso_Basico                 1   4966.2 5026.2
## - Cuot_Men_Tdc_Cred_Rot          1   4966.4 5026.4
## - Sal_Créd_Viv_Veh               1   4966.5 5026.5
## - `End_Max_ Vec_Salario`         1   4966.5 5026.5
## - CumpleTiempoVincul             1   4966.6 5026.6
## - Sal_TDC_Cred_Rot               1   4967.1 5027.1
## <none>                               4965.2 5027.2
## - MoraObliVig                    1   4968.4 5028.4
## - Mont_Credito                   1   4969.7 5029.7
## - Porc_Ded_Nom                   1   4969.9 5029.9
## - Punt_Acierta                   1   4970.6 5030.6
## - ConyLabora                     1   4972.3 5032.3
## - Porc_Cap_Pago                  1   4973.4 5033.4
## - NivelEduc                      1   4973.7 5033.7
## - Porc_Gast_Fina                 1   4975.1 5035.1
## - CateAfil                       1   4975.5 5035.5
## - sexo2                          1   4976.2 5036.2
## - Edad                           1   4976.2 5036.2
## - TipoContrato                   1   4976.3 5036.3
## - Tot_Cuot_Pag                   1   4979.6 5039.6
## - Porc_Proy_Liquid_Resp_Credito  1   5019.6 5079.6
## 
## Step:  AIC=5025.69
## Default ~ Edad + Ingreso_Basico + Aux_Transporte + Otros_Ingresos + 
##     Base_70_Ingr_consti_Sal + Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + 
##     Cuot_Mens_Otras_Oblig + Sal_Disp + Sal_Obli_Ded_Nomina + 
##     Sal_Créd_Viv_Veh + Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + 
##     Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + Porc_Cap_Pago + 
##     Porc_Gast_Fina + `End_Max_ Vec_Salario` + Mont_Credito + 
##     CateAfil + sexo2 + ConyLabora + TipoVivienda + NivelEduc + 
##     TipoContrato + CumpleTiempoVincul + MoraObliVig
## 
##                                 Df Deviance    AIC
## - TipoVivienda                   1   4966.4 5024.4
## - Sal_Obli_Ded_Nomina            1   4966.5 5024.5
## - Aux_Transporte                 1   4966.6 5024.6
## - Base_70_Ingr_consti_Sal        1   4966.7 5024.7
## - Cuot_Mens_Otras_Oblig          1   4966.7 5024.7
## - Tot_Gast_Fami                  1   4966.7 5024.7
## - Otros_Ingresos                 1   4966.7 5024.7
## - Sal_Disp                       1   4966.7 5024.7
## - Ded_Nomina                     1   4966.7 5024.7
## - Ingreso_Basico                 1   4966.7 5024.7
## - Cuot_Men_Tdc_Cred_Rot          1   4966.9 5024.9
## - CumpleTiempoVincul             1   4966.9 5024.9
## - Sal_Créd_Viv_Veh               1   4967.0 5025.0
## - Sal_TDC_Cred_Rot               1   4967.5 5025.5
## - `End_Max_ Vec_Salario`         1   4967.6 5025.6
## <none>                               4965.7 5025.7
## - MoraObliVig                    1   4968.7 5026.7
## - Porc_Ded_Nom                   1   4970.0 5028.0
## - Mont_Credito                   1   4971.3 5029.3
## - Punt_Acierta                   1   4971.4 5029.4
## - ConyLabora                     1   4972.4 5030.4
## - Porc_Cap_Pago                  1   4973.5 5031.5
## - NivelEduc                      1   4974.1 5032.1
## - Porc_Gast_Fina                 1   4975.1 5033.1
## - sexo2                          1   4976.6 5034.6
## - CateAfil                       1   4976.6 5034.6
## - TipoContrato                   1   4977.0 5035.0
## - Edad                           1   4977.1 5035.1
## - Tot_Cuot_Pag                   1   4983.0 5041.0
## - Porc_Proy_Liquid_Resp_Credito  1   5019.7 5077.7
## 
## Step:  AIC=5024.39
## Default ~ Edad + Ingreso_Basico + Aux_Transporte + Otros_Ingresos + 
##     Base_70_Ingr_consti_Sal + Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + 
##     Cuot_Mens_Otras_Oblig + Sal_Disp + Sal_Obli_Ded_Nomina + 
##     Sal_Créd_Viv_Veh + Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + 
##     Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + Porc_Cap_Pago + 
##     Porc_Gast_Fina + `End_Max_ Vec_Salario` + Mont_Credito + 
##     CateAfil + sexo2 + ConyLabora + NivelEduc + TipoContrato + 
##     CumpleTiempoVincul + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Sal_Obli_Ded_Nomina            1   4967.2 5023.2
## - Aux_Transporte                 1   4967.3 5023.3
## - Base_70_Ingr_consti_Sal        1   4967.4 5023.4
## - Cuot_Mens_Otras_Oblig          1   4967.4 5023.4
## - Tot_Gast_Fami                  1   4967.4 5023.4
## - Otros_Ingresos                 1   4967.4 5023.4
## - Sal_Disp                       1   4967.4 5023.4
## - Ded_Nomina                     1   4967.4 5023.4
## - Ingreso_Basico                 1   4967.4 5023.4
## - Cuot_Men_Tdc_Cred_Rot          1   4967.6 5023.6
## - CumpleTiempoVincul             1   4967.6 5023.6
## - Sal_Créd_Viv_Veh               1   4967.9 5023.9
## - Sal_TDC_Cred_Rot               1   4968.2 5024.2
## - `End_Max_ Vec_Salario`         1   4968.3 5024.3
## <none>                               4966.4 5024.4
## - MoraObliVig                    1   4969.5 5025.5
## - Porc_Ded_Nom                   1   4970.5 5026.5
## - Mont_Credito                   1   4971.9 5027.9
## - Punt_Acierta                   1   4972.1 5028.1
## - ConyLabora                     1   4973.0 5029.0
## - Porc_Cap_Pago                  1   4974.1 5030.1
## - NivelEduc                      1   4974.8 5030.8
## - Porc_Gast_Fina                 1   4975.7 5031.7
## - sexo2                          1   4977.4 5033.4
## - CateAfil                       1   4977.4 5033.4
## - TipoContrato                   1   4977.8 5033.8
## - Edad                           1   4978.9 5034.9
## - Tot_Cuot_Pag                   1   4983.5 5039.5
## - Porc_Proy_Liquid_Resp_Credito  1   5021.0 5077.0
## 
## Step:  AIC=5023.18
## Default ~ Edad + Ingreso_Basico + Aux_Transporte + Otros_Ingresos + 
##     Base_70_Ingr_consti_Sal + Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + 
##     Cuot_Mens_Otras_Oblig + Sal_Disp + Sal_Créd_Viv_Veh + Sal_TDC_Cred_Rot + 
##     Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + CumpleTiempoVincul + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Aux_Transporte                 1   4968.1 5022.1
## - Base_70_Ingr_consti_Sal        1   4968.2 5022.2
## - Cuot_Mens_Otras_Oblig          1   4968.2 5022.2
## - Otros_Ingresos                 1   4968.2 5022.2
## - Sal_Disp                       1   4968.2 5022.2
## - Tot_Gast_Fami                  1   4968.2 5022.2
## - Ded_Nomina                     1   4968.2 5022.2
## - Ingreso_Basico                 1   4968.2 5022.2
## - CumpleTiempoVincul             1   4968.3 5022.3
## - Cuot_Men_Tdc_Cred_Rot          1   4968.3 5022.3
## - Sal_Créd_Viv_Veh               1   4968.4 5022.4
## - Sal_TDC_Cred_Rot               1   4968.7 5022.7
## <none>                               4967.2 5023.2
## - MoraObliVig                    1   4970.3 5024.3
## - `End_Max_ Vec_Salario`         1   4970.7 5024.7
## - Porc_Ded_Nom                   1   4971.8 5025.8
## - Punt_Acierta                   1   4972.9 5026.9
## - ConyLabora                     1   4973.9 5027.9
## - Mont_Credito                   1   4974.3 5028.3
## - Porc_Cap_Pago                  1   4974.8 5028.8
## - NivelEduc                      1   4975.8 5029.8
## - Porc_Gast_Fina                 1   4976.6 5030.6
## - sexo2                          1   4978.2 5032.2
## - CateAfil                       1   4978.4 5032.4
## - TipoContrato                   1   4978.5 5032.5
## - Edad                           1   4980.1 5034.1
## - Tot_Cuot_Pag                   1   4984.8 5038.8
## - Porc_Proy_Liquid_Resp_Credito  1   5021.0 5075.0
## 
## Step:  AIC=5022.13
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Base_70_Ingr_consti_Sal + 
##     Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Sal_Créd_Viv_Veh + Sal_TDC_Cred_Rot + Punt_Acierta + 
##     Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + 
##     Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + CumpleTiempoVincul + MoraObliVig
## 
##                                 Df Deviance    AIC
## - CumpleTiempoVincul             1   4969.3 5021.3
## - Sal_Créd_Viv_Veh               1   4969.4 5021.4
## - Sal_TDC_Cred_Rot               1   4969.6 5021.6
## - Base_70_Ingr_consti_Sal        1   4970.0 5022.0
## <none>                               4968.1 5022.1
## - Cuot_Mens_Otras_Oblig          1   4970.5 5022.5
## - Cuot_Men_Tdc_Cred_Rot          1   4970.6 5022.6
## - Tot_Gast_Fami                  1   4970.9 5022.9
## - Sal_Disp                       1   4971.1 5023.1
## - Otros_Ingresos                 1   4971.1 5023.1
## - MoraObliVig                    1   4971.3 5023.3
## - `End_Max_ Vec_Salario`         1   4971.6 5023.6
## - Ded_Nomina                     1   4971.8 5023.8
## - Ingreso_Basico                 1   4972.1 5024.1
## - Porc_Ded_Nom                   1   4972.7 5024.7
## - Punt_Acierta                   1   4973.7 5025.7
## - ConyLabora                     1   4974.9 5026.9
## - Mont_Credito                   1   4975.3 5027.3
## - Porc_Cap_Pago                  1   4975.8 5027.8
## - NivelEduc                      1   4976.8 5028.8
## - Porc_Gast_Fina                 1   4977.6 5029.6
## - sexo2                          1   4979.0 5031.0
## - CateAfil                       1   4979.3 5031.3
## - TipoContrato                   1   4979.5 5031.5
## - Edad                           1   4981.1 5033.1
## - Tot_Cuot_Pag                   1   4985.8 5037.8
## - Porc_Proy_Liquid_Resp_Credito  1   5022.0 5074.0
## 
## Step:  AIC=5021.28
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Base_70_Ingr_consti_Sal + 
##     Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Sal_Créd_Viv_Veh + Sal_TDC_Cred_Rot + Punt_Acierta + 
##     Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + 
##     Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Sal_Créd_Viv_Veh               1   4970.5 5020.5
## - Sal_TDC_Cred_Rot               1   4970.8 5020.8
## - Base_70_Ingr_consti_Sal        1   4971.1 5021.1
## <none>                               4969.3 5021.3
## - Cuot_Mens_Otras_Oblig          1   4971.6 5021.6
## - Cuot_Men_Tdc_Cred_Rot          1   4971.7 5021.7
## - Tot_Gast_Fami                  1   4972.0 5022.0
## - Sal_Disp                       1   4972.2 5022.2
## - Otros_Ingresos                 1   4972.2 5022.2
## - MoraObliVig                    1   4972.5 5022.5
## - `End_Max_ Vec_Salario`         1   4972.6 5022.6
## - Ded_Nomina                     1   4972.9 5022.9
## - Ingreso_Basico                 1   4973.2 5023.2
## - Porc_Ded_Nom                   1   4974.1 5024.1
## - Punt_Acierta                   1   4974.8 5024.8
## - ConyLabora                     1   4976.2 5026.2
## - Mont_Credito                   1   4976.9 5026.9
## - Porc_Cap_Pago                  1   4977.1 5027.1
## - NivelEduc                      1   4977.6 5027.6
## - Porc_Gast_Fina                 1   4978.8 5028.8
## - TipoContrato                   1   4979.5 5029.5
## - sexo2                          1   4980.1 5030.1
## - CateAfil                       1   4980.7 5030.7
## - Edad                           1   4983.1 5033.1
## - Tot_Cuot_Pag                   1   4987.5 5037.5
## - Porc_Proy_Liquid_Resp_Credito  1   5022.9 5072.9
## 
## Step:  AIC=5020.53
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Base_70_Ingr_consti_Sal + 
##     Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Sal_TDC_Cred_Rot + Punt_Acierta + Tot_Cuot_Pag + 
##     Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + Porc_Cap_Pago + 
##     Porc_Gast_Fina + `End_Max_ Vec_Salario` + Mont_Credito + 
##     CateAfil + sexo2 + ConyLabora + NivelEduc + TipoContrato + 
##     MoraObliVig
## 
##                                 Df Deviance    AIC
## - Sal_TDC_Cred_Rot               1   4972.0 5020.0
## - Base_70_Ingr_consti_Sal        1   4972.3 5020.3
## <none>                               4970.5 5020.5
## - Cuot_Mens_Otras_Oblig          1   4972.9 5020.9
## - Cuot_Men_Tdc_Cred_Rot          1   4973.0 5021.0
## - Tot_Gast_Fami                  1   4973.1 5021.1
## - `End_Max_ Vec_Salario`         1   4973.1 5021.1
## - Sal_Disp                       1   4973.3 5021.3
## - Otros_Ingresos                 1   4973.4 5021.4
## - MoraObliVig                    1   4973.8 5021.8
## - Ded_Nomina                     1   4974.4 5022.4
## - Ingreso_Basico                 1   4974.4 5022.4
## - Porc_Ded_Nom                   1   4975.7 5023.7
## - Punt_Acierta                   1   4976.3 5024.3
## - Mont_Credito                   1   4977.4 5025.4
## - ConyLabora                     1   4977.5 5025.5
## - Porc_Cap_Pago                  1   4978.2 5026.2
## - NivelEduc                      1   4978.9 5026.9
## - Porc_Gast_Fina                 1   4979.8 5027.8
## - TipoContrato                   1   4980.8 5028.8
## - sexo2                          1   4981.2 5029.2
## - CateAfil                       1   4981.9 5029.9
## - Edad                           1   4984.3 5032.3
## - Tot_Cuot_Pag                   1   4989.4 5037.4
## - Porc_Proy_Liquid_Resp_Credito  1   5025.6 5073.6
## 
## Step:  AIC=5019.99
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Base_70_Ingr_consti_Sal + 
##     Ded_Nomina + Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Base_70_Ingr_consti_Sal        1   4973.7 5019.7
## <none>                               4972.0 5020.0
## - Cuot_Men_Tdc_Cred_Rot          1   4974.2 5020.2
## - Cuot_Mens_Otras_Oblig          1   4974.3 5020.3
## - Tot_Gast_Fami                  1   4974.4 5020.4
## - `End_Max_ Vec_Salario`         1   4974.6 5020.6
## - Otros_Ingresos                 1   4974.7 5020.7
## - Sal_Disp                       1   4974.7 5020.7
## - MoraObliVig                    1   4975.3 5021.3
## - Ingreso_Basico                 1   4975.8 5021.8
## - Ded_Nomina                     1   4975.8 5021.8
## - Porc_Ded_Nom                   1   4977.2 5023.2
## - Punt_Acierta                   1   4977.7 5023.7
## - ConyLabora                     1   4978.6 5024.6
## - Mont_Credito                   1   4978.7 5024.7
## - Porc_Cap_Pago                  1   4979.5 5025.5
## - NivelEduc                      1   4980.6 5026.6
## - Porc_Gast_Fina                 1   4981.0 5027.0
## - TipoContrato                   1   4982.3 5028.3
## - sexo2                          1   4982.6 5028.6
## - CateAfil                       1   4983.7 5029.7
## - Edad                           1   4985.8 5031.8
## - Tot_Cuot_Pag                   1   4990.7 5036.7
## - Porc_Proy_Liquid_Resp_Credito  1   5026.7 5072.7
## 
## Step:  AIC=5019.71
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Ded_Nomina + 
##     Tot_Gast_Fami + Cuot_Men_Tdc_Cred_Rot + Cuot_Mens_Otras_Oblig + 
##     Sal_Disp + Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Cuot_Men_Tdc_Cred_Rot          1   4974.2 5018.2
## - Tot_Gast_Fami                  1   4974.4 5018.4
## - Cuot_Mens_Otras_Oblig          1   4974.5 5018.5
## <none>                               4973.7 5019.7
## - Sal_Disp                       1   4975.9 5019.9
## - Otros_Ingresos                 1   4976.0 5020.0
## - `End_Max_ Vec_Salario`         1   4976.4 5020.4
## - MoraObliVig                    1   4977.0 5021.0
## - Porc_Ded_Nom                   1   4978.2 5022.2
## - ConyLabora                     1   4979.4 5023.4
## - Punt_Acierta                   1   4979.7 5023.7
## - Porc_Cap_Pago                  1   4980.0 5024.0
## - Ded_Nomina                     1   4980.1 5024.1
## - Mont_Credito                   1   4980.5 5024.5
## - Porc_Gast_Fina                 1   4981.5 5025.5
## - NivelEduc                      1   4982.8 5026.8
## - TipoContrato                   1   4983.5 5027.5
## - CateAfil                       1   4983.8 5027.8
## - sexo2                          1   4984.7 5028.7
## - Ingreso_Basico                 1   4985.5 5029.5
## - Edad                           1   4987.0 5031.0
## - Tot_Cuot_Pag                   1   4991.5 5035.5
## - Porc_Proy_Liquid_Resp_Credito  1   5028.3 5072.3
## 
## Step:  AIC=5018.2
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Ded_Nomina + 
##     Tot_Gast_Fami + Cuot_Mens_Otras_Oblig + Sal_Disp + Punt_Acierta + 
##     Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + 
##     Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Cuot_Mens_Otras_Oblig          1   4974.6 5016.6
## - Tot_Gast_Fami                  1   4974.9 5016.9
## - Sal_Disp                       1   4975.9 5017.9
## - Otros_Ingresos                 1   4976.0 5018.0
## <none>                               4974.2 5018.2
## - `End_Max_ Vec_Salario`         1   4976.9 5018.9
## - MoraObliVig                    1   4977.6 5019.6
## - Porc_Ded_Nom                   1   4979.1 5021.1
## - Ded_Nomina                     1   4980.1 5022.1
## - Punt_Acierta                   1   4980.2 5022.2
## - ConyLabora                     1   4980.6 5022.6
## - Porc_Cap_Pago                  1   4980.6 5022.6
## - Mont_Credito                   1   4980.9 5022.9
## - Porc_Gast_Fina                 1   4982.0 5024.0
## - NivelEduc                      1   4983.2 5025.2
## - TipoContrato                   1   4984.0 5026.0
## - CateAfil                       1   4984.5 5026.5
## - sexo2                          1   4985.1 5027.1
## - Ingreso_Basico                 1   4985.7 5027.7
## - Edad                           1   4987.5 5029.5
## - Tot_Cuot_Pag                   1   4992.3 5034.3
## - Porc_Proy_Liquid_Resp_Credito  1   5028.8 5070.8
## 
## Step:  AIC=5016.59
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Ded_Nomina + 
##     Tot_Gast_Fami + Sal_Disp + Punt_Acierta + Tot_Cuot_Pag + 
##     Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + Porc_Cap_Pago + 
##     Porc_Gast_Fina + `End_Max_ Vec_Salario` + Mont_Credito + 
##     CateAfil + sexo2 + ConyLabora + NivelEduc + TipoContrato + 
##     MoraObliVig
## 
##                                 Df Deviance    AIC
## - Tot_Gast_Fami                  1   4975.1 5015.1
## - Otros_Ingresos                 1   4976.4 5016.4
## <none>                               4974.6 5016.6
## - Sal_Disp                       1   4976.6 5016.6
## - `End_Max_ Vec_Salario`         1   4977.3 5017.3
## - MoraObliVig                    1   4977.9 5017.9
## - Ded_Nomina                     1   4980.2 5020.2
## - Punt_Acierta                   1   4980.5 5020.5
## - Porc_Ded_Nom                   1   4980.6 5020.6
## - Mont_Credito                   1   4981.2 5021.2
## - Porc_Cap_Pago                  1   4981.5 5021.5
## - ConyLabora                     1   4982.1 5022.1
## - Porc_Gast_Fina                 1   4982.7 5022.7
## - NivelEduc                      1   4983.4 5023.4
## - TipoContrato                   1   4984.5 5024.5
## - CateAfil                       1   4985.3 5025.3
## - sexo2                          1   4985.3 5025.3
## - Edad                           1   4988.0 5028.0
## - Ingreso_Basico                 1   4991.7 5031.7
## - Tot_Cuot_Pag                   1   4993.9 5033.9
## - Porc_Proy_Liquid_Resp_Credito  1   5029.0 5069.0
## 
## Step:  AIC=5015.14
## Default ~ Edad + Ingreso_Basico + Otros_Ingresos + Ded_Nomina + 
##     Sal_Disp + Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Otros_Ingresos                 1   4976.6 5014.6
## - Sal_Disp                       1   4976.9 5014.9
## <none>                               4975.1 5015.1
## - `End_Max_ Vec_Salario`         1   4977.9 5015.9
## - MoraObliVig                    1   4978.5 5016.5
## - Ded_Nomina                     1   4981.1 5019.1
## - Punt_Acierta                   1   4981.2 5019.2
## - Mont_Credito                   1   4981.9 5019.9
## - ConyLabora                     1   4982.2 5020.2
## - Porc_Ded_Nom                   1   4982.6 5020.6
## - Porc_Cap_Pago                  1   4983.6 5021.6
## - NivelEduc                      1   4983.9 5021.9
## - TipoContrato                   1   4985.0 5023.0
## - Porc_Gast_Fina                 1   4985.3 5023.3
## - sexo2                          1   4985.8 5023.8
## - CateAfil                       1   4987.0 5025.0
## - Edad                           1   4988.7 5026.7
## - Ingreso_Basico                 1   4994.0 5032.0
## - Tot_Cuot_Pag                   1   4997.2 5035.2
## - Porc_Proy_Liquid_Resp_Credito  1   5030.2 5068.2
## 
## Step:  AIC=5014.58
## Default ~ Edad + Ingreso_Basico + Ded_Nomina + Sal_Disp + Punt_Acierta + 
##     Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + 
##     Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig
## 
##                                 Df Deviance    AIC
## - Sal_Disp                       1   4977.1 5013.1
## <none>                               4976.6 5014.6
## - `End_Max_ Vec_Salario`         1   4979.4 5015.4
## - MoraObliVig                    1   4979.9 5015.9
## - Ded_Nomina                     1   4981.9 5017.9
## - Punt_Acierta                   1   4982.9 5018.9
## - Mont_Credito                   1   4983.8 5019.8
## - NivelEduc                      1   4985.2 5021.2
## - ConyLabora                     1   4986.1 5022.1
## - Porc_Ded_Nom                   1   4986.1 5022.1
## - TipoContrato                   1   4986.4 5022.4
## - Porc_Cap_Pago                  1   4987.1 5023.1
## - sexo2                          1   4987.5 5023.5
## - CateAfil                       1   4988.9 5024.9
## - Edad                           1   4990.1 5026.1
## - Porc_Gast_Fina                 1   4990.1 5026.1
## - Ingreso_Basico                 1   4994.6 5030.6
## - Tot_Cuot_Pag                   1   5002.1 5038.1
## - Porc_Proy_Liquid_Resp_Credito  1   5030.9 5066.9
## 
## Step:  AIC=5013.13
## Default ~ Edad + Ingreso_Basico + Ded_Nomina + Punt_Acierta + 
##     Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + Porc_Ded_Nom + 
##     Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig
## 
##                                 Df Deviance    AIC
## <none>                               4977.1 5013.1
## - `End_Max_ Vec_Salario`         1   4979.7 5013.7
## - MoraObliVig                    1   4980.5 5014.5
## - Ded_Nomina                     1   4982.0 5016.0
## - Punt_Acierta                   1   4983.7 5017.7
## - Mont_Credito                   1   4984.1 5018.1
## - NivelEduc                      1   4986.1 5020.1
## - Porc_Ded_Nom                   1   4986.6 5020.6
## - ConyLabora                     1   4987.0 5021.0
## - TipoContrato                   1   4987.1 5021.1
## - Porc_Cap_Pago                  1   4987.4 5021.4
## - sexo2                          1   4987.9 5021.9
## - CateAfil                       1   4990.8 5024.8
## - Edad                           1   4990.9 5024.9
## - Porc_Gast_Fina                 1   4991.4 5025.4
## - Ingreso_Basico                 1   4994.6 5028.6
## - Tot_Cuot_Pag                   1   5005.0 5039.0
## - Porc_Proy_Liquid_Resp_Credito  1   5031.3 5065.3
mod_2
## 
## Call:  glm(formula = Default ~ Edad + Ingreso_Basico + Ded_Nomina + 
##     Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig, family = "binomial", data = datos)
## 
## Coefficients:
##                   (Intercept)                           Edad  
##                     1.921e+00                     -1.696e-02  
##                Ingreso_Basico                     Ded_Nomina  
##                     6.821e-07                     -8.242e-07  
##                  Punt_Acierta                   Tot_Cuot_Pag  
##                    -5.218e-04                     -7.462e-06  
## Porc_Proy_Liquid_Resp_Credito                   Porc_Ded_Nom  
##                    -4.043e-01                      4.033e+00  
##                 Porc_Cap_Pago                 Porc_Gast_Fina  
##                    -5.558e+00                      6.378e+00  
##        `End_Max_ Vec_Salario`                   Mont_Credito  
##                    -4.140e-02                      7.578e-08  
##                      CateAfil                          sexo2  
##                    -3.502e-01                      2.972e-01  
##                    ConyLabora                      NivelEduc  
##                    -8.900e-01                     -1.340e-01  
##                  TipoContrato                    MoraObliVig  
##                    -5.176e-02                     -3.197e-02  
## 
## Degrees of Freedom: 15812 Total (i.e. Null);  15795 Residual
## Null Deviance:       5251 
## Residual Deviance: 4977  AIC: 5013
summary(mod_2)
## 
## Call:
## glm(formula = Default ~ Edad + Ingreso_Basico + Ded_Nomina + 
##     Punt_Acierta + Tot_Cuot_Pag + Porc_Proy_Liquid_Resp_Credito + 
##     Porc_Ded_Nom + Porc_Cap_Pago + Porc_Gast_Fina + `End_Max_ Vec_Salario` + 
##     Mont_Credito + CateAfil + sexo2 + ConyLabora + NivelEduc + 
##     TipoContrato + MoraObliVig, family = "binomial", data = datos)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.4089  -0.3227  -0.2608  -0.1944   3.5998  
## 
## Coefficients:
##                                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    1.921e+00  8.131e-01   2.363 0.018130 *  
## Edad                          -1.696e-02  4.660e-03  -3.640 0.000273 ***
## Ingreso_Basico                 6.821e-07  1.546e-07   4.411 1.03e-05 ***
## Ded_Nomina                    -8.242e-07  4.001e-07  -2.060 0.039379 *  
## Punt_Acierta                  -5.218e-04  1.979e-04  -2.637 0.008367 ** 
## Tot_Cuot_Pag                  -7.462e-06  1.507e-06  -4.953 7.31e-07 ***
## Porc_Proy_Liquid_Resp_Credito -4.043e-01  6.601e-02  -6.125 9.06e-10 ***
## Porc_Ded_Nom                   4.033e+00  1.293e+00   3.118 0.001818 ** 
## Porc_Cap_Pago                 -5.558e+00  1.715e+00  -3.241 0.001193 ** 
## Porc_Gast_Fina                 6.378e+00  1.664e+00   3.832 0.000127 ***
## `End_Max_ Vec_Salario`        -4.140e-02  2.628e-02  -1.576 0.115140    
## Mont_Credito                   7.578e-08  2.886e-08   2.626 0.008652 ** 
## CateAfil                      -3.502e-01  9.438e-02  -3.711 0.000207 ***
## sexo2                          2.972e-01  9.133e-02   3.254 0.001136 ** 
## ConyLabora                    -8.900e-01  2.810e-01  -3.167 0.001542 ** 
## NivelEduc                     -1.340e-01  4.513e-02  -2.968 0.002994 ** 
## TipoContrato                  -5.176e-02  1.632e-02  -3.171 0.001518 ** 
## MoraObliVig                   -3.197e-02  1.691e-02  -1.890 0.058749 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 5250.7  on 15812  degrees of freedom
## Residual deviance: 4977.1  on 15795  degrees of freedom
## AIC: 5013.1
## 
## Number of Fisher Scoring iterations: 7

2.3. Usando Caret y Cross Validation para las variables

require(caret)
## Loading required package: caret
## Loading required package: ggplot2
## Loading required package: lattice

2.3.1. Modelo de Regresión logística

control=trainControl(method = "cv",number = 10)

mod_caret=train(Default~.,data=datos,method="glm",family="binomial",trControl=control,metric="Accuracy")
varImp(mod_caret)
## glm variable importance
## 
##   only 20 most important variables shown (out of 35)
## 
##                               Overall
## Porc_Proy_Liquid_Resp_Credito  100.00
## Tot_Cuot_Pag                    84.31
## TipoContrato                    75.30
## sexo2                           72.79
## Porc_Gast_Fina                  70.67
## CateAfil                        70.03
## Edad                            67.45
## Porc_Cap_Pago                   62.75
## NivelEduc                       59.09
## ConyLabora                      57.05
## Punt_Acierta                    52.16
## Mont_Credito                    48.55
## Porc_Ded_Nom                    47.89
## MoraObliVig                     41.17
## Sal_TDC_Cred_Rot                32.19
## `\\`End_Max_ Vec_Salario\\``    28.61
## CumpleTiempoVincul              26.41
## TipoVivienda                    19.92
## Sal_Créd_Viv_Veh                17.88
## Sal_Obli_Ded_Nomina             17.53
plot(varImp(mod_caret))

most_impo=varImp(mod_caret)
most_impo
## glm variable importance
## 
##   only 20 most important variables shown (out of 35)
## 
##                               Overall
## Porc_Proy_Liquid_Resp_Credito  100.00
## Tot_Cuot_Pag                    84.31
## TipoContrato                    75.30
## sexo2                           72.79
## Porc_Gast_Fina                  70.67
## CateAfil                        70.03
## Edad                            67.45
## Porc_Cap_Pago                   62.75
## NivelEduc                       59.09
## ConyLabora                      57.05
## Punt_Acierta                    52.16
## Mont_Credito                    48.55
## Porc_Ded_Nom                    47.89
## MoraObliVig                     41.17
## Sal_TDC_Cred_Rot                32.19
## `\\`End_Max_ Vec_Salario\\``    28.61
## CumpleTiempoVincul              26.41
## TipoVivienda                    19.92
## Sal_Créd_Viv_Veh                17.88
## Sal_Obli_Ded_Nomina             17.53

Variables Top

datos=data.frame(datos)
mod_top=glm(Default~Porc_Proy_Liquid_Resp_Credito+Tot_Cuot_Pag+TipoContrato+sexo2+Porc_Gast_Fina+CateAfil+Edad+Porc_Cap_Pago+NivelEduc+ConyLabora+Punt_Acierta+Mont_Credito+Porc_Ded_Nom+MoraObliVig,data=datos,family = "binomial")

res_coef=matrix(NA,nrow = 1000,ncol = 14)

for(i in 1:1000){


unos=which(datos$Default==1)
ceros=sample(which(datos$Default==0),623)
datos_balanceo=datos[c(unos,ceros),]

mod_top_balanceo=glm(Default~Porc_Proy_Liquid_Resp_Credito+Tot_Cuot_Pag+TipoContrato+sexo2+Porc_Gast_Fina+CateAfil+Edad+Porc_Cap_Pago+NivelEduc+ConyLabora+Punt_Acierta+Mont_Credito+Porc_Ded_Nom,data=datos_balanceo,family = "binomial")

res_coef[i,]=round(mod_top_balanceo$coefficients,8)

}
res_coef=data.frame(res_coef)
names(res_coef)=names(mod_top_balanceo$coefficients)
summary(mod_top_balanceo)
## 
## Call:
## glm(formula = Default ~ Porc_Proy_Liquid_Resp_Credito + Tot_Cuot_Pag + 
##     TipoContrato + sexo2 + Porc_Gast_Fina + CateAfil + Edad + 
##     Porc_Cap_Pago + NivelEduc + ConyLabora + Punt_Acierta + Mont_Credito + 
##     Porc_Ded_Nom, family = "binomial", data = datos_balanceo)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.8329  -1.1376   0.2915   1.0867   2.3904  
## 
## Coefficients:
##                                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                    3.668e+00  9.934e-01   3.692 0.000223 ***
## Porc_Proy_Liquid_Resp_Credito -3.377e-01  7.953e-02  -4.246 2.18e-05 ***
## Tot_Cuot_Pag                  -2.899e-06  1.529e-06  -1.896 0.058004 .  
## TipoContrato                  -2.312e-02  2.338e-02  -0.989 0.322714    
## sexo2                          2.493e-01  1.293e-01   1.928 0.053884 .  
## Porc_Gast_Fina                 2.827e+00  2.119e+00   1.334 0.182211    
## CateAfil                      -1.788e-01  1.285e-01  -1.391 0.164286    
## Edad                          -1.374e-02  6.315e-03  -2.175 0.029632 *  
## Porc_Cap_Pago                 -2.745e+00  2.214e+00  -1.240 0.215076    
## NivelEduc                     -4.967e-02  6.248e-02  -0.795 0.426605    
## ConyLabora                    -5.039e-01  3.673e-01  -1.372 0.170145    
## Punt_Acierta                  -9.139e-04  3.258e-04  -2.805 0.005025 ** 
## Mont_Credito                   3.361e-08  2.882e-08   1.166 0.243513    
## Porc_Ded_Nom                   3.045e-01  1.554e+00   0.196 0.844599    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1727.3  on 1245  degrees of freedom
## Residual deviance: 1618.5  on 1232  degrees of freedom
## AIC: 1646.5
## 
## Number of Fisher Scoring iterations: 4

3. Etapa 3: Balanceo de datos Oversampling

require(reticulate)
# Importamos la librerías
import pandas as pd
import numpy as np

import matplotlib.pyplot as plt
#%matplotlib inline
import seaborn as sns

import warnings
warnings.filterwarnings('ignore')

from imblearn.over_sampling import SMOTE
from imblearn.pipeline import make_pipeline
from pylab import rcParams
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.metrics import precision_score, recall_score
from sklearn.metrics import f1_score, roc_auc_score, roc_curve
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV

Con el método de reducción de dimensionalidad Caret y Cross Validation para las variables, seleccionamos las variables más importantes:

Default = Porc_Proy_Liquid_Resp_Credito + Tot_Cuot_Pag + TipoContrato + sexo2 + Porc_Gast_Fina + CateAfil + Edad + Porc_Cap_Pago + NivelEduc + ConyLabora + Punt_Acierta + Mont_Credito + Porc_Ded_Nom

df = pd.read_excel("D:/01_PUJ/00_Trabajo_de_grado/Data/DatosBD27052023RedDim3.xlsx")
df.head()
##    Edad  Punt_Acierta   Tot_Cuot_Pag  ...  NivelEduc  TipoContrato  Default
## 0    40           683   96516.136875  ...          2             7        0
## 1    57           803   72842.367453  ...          2             7        0
## 2    31           838  107736.180180  ...          3             7        0
## 3    52           665  116714.195195  ...          5             7        0
## 4    33           794  100158.255248  ...          2             7        0
## 
## [5 rows x 13 columns]
df.shape
## (15813, 13)
df.describe()
##                Edad  Punt_Acierta  ...  TipoContrato       Default
## count  15813.000000  15813.000000  ...  15813.000000  15813.000000
## mean      35.717764    683.636438  ...      5.323025      0.039398
## std       10.604924    186.269795  ...      2.449206      0.194546
## min       18.000000      0.000000  ...      1.000000      0.000000
## 25%       27.000000    667.000000  ...      2.000000      0.000000
## 50%       34.000000    727.000000  ...      7.000000      0.000000
## 75%       43.000000    781.000000  ...      7.000000      0.000000
## max       69.000000    938.000000  ...      7.000000      1.000000
## 
## [8 rows x 13 columns]

Se hace tratamiento de valores faltantes

df_missing_values = df.isnull().sum()
df_missing_values 
## Edad                             0
## Punt_Acierta                     0
## Tot_Cuot_Pag                     0
## Porc_Proy_Liquid_Resp_Credito    0
## Porc_Cap_Pago                    0
## Porc_Gast_Fina                   0
## Mont_Credito                     0
## CateAfil                         0
## sexo2                            0
## ConyLabora                       0
## NivelEduc                        0
## TipoContrato                     0
## Default                          0
## dtype: int64

Análisis de distribución de datos

classes = df['Default'].value_counts()
classes
## 0    15190
## 1      623
## Name: Default, dtype: int64
# Creamos marco de datos de créditos "En Mora"
data_EnMora = df[df['Default'] == 1]
# Creamos marco de datos de créditos "Al Dia"
data_AlDia = df[df['Default'] == 0]

Dividimos en Entrenamiento y Test

# Importamos librería
from sklearn.model_selection import train_test_split
# Introducir variables de características en X
X = df.drop(['Default'], axis=1)
# Poniendo la variable objetivo en y

y = df['Default']
# División de datos en Entrenamiento y Test de prueba 80:20

X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8, test_size=0.2, random_state=100)

Balanceo de datos son el Método SMOTE OVERSAMPLING

unique, count = np.unique(y_train, return_counts=True)
Y_train_dict_value_count = { k:v for (k,v) in zip(unique, count)}
Y_train_dict_value_count
## {0: 12148, 1: 502}
sm = SMOTE(random_state=12, sampling_strategy = 1.0)
x_train_res, y_train_res = sm.fit_resample(X_train, y_train)
unique, count = np.unique(y_train_res, return_counts=True)
y_train_smote_value_count = { k:v for (k,v) in zip(unique, count)}
y_train_smote_value_count
## {0: 12148, 1: 12148}

4. Etapa 4: Modelado

  1. Dividir el conjunto de datos en conjuntos de entrenamiento y test.

  2. Realizar el entrenamiento del modelo de regresión logística utilizando para ello el conjunto de entrenamiento y compararlo con los modelos XGBoost, árbol de decisión, Bosque aleatorio.

  3. Aplicar el modelo construido a los datos del conjunto de test.

  4. Cálculo de una métrica de desempeño para evaluar la calidad del modelo en sus prediciones sobre el conjunto de test.

# Importando métricas

from sklearn import metrics
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay, classification_report, f1_score
results = pd.DataFrame(columns=['Model Name', 'Accuracy', 'F1-score', 'ROC'])
# Función de curva ROC

def draw_roc( actual, probs ):
    fpr, tpr, thresholds = metrics.roc_curve( actual, probs,
                                              drop_intermediate = False )
    auc_score = metrics.roc_auc_score( actual, probs )
    plt.figure(figsize=(5, 5))
    plt.plot( fpr, tpr, label='ROC curve (area = %0.2f)' % auc_score )
    plt.plot([0, 1], [0, 1], 'k--')
    plt.xlim([0.0, 1.0])
    plt.ylim([0.0, 1.05])
    plt.xlabel('False Positive Rate or [1 - True Negative Rate]')
    plt.ylabel('True Positive Rate')
    plt.title('Receiver operating characteristic example')
    plt.legend(loc="lower right")
    plt.show()

    return None

4.1. Modelo de Regresión Logística

# Importando el módulo de regresión logística de scikit

from sklearn.linear_model import LogisticRegression
# Instanciar el modelo con mejor C

logistic = LogisticRegression(C=0.01)
# Ajuste el modelo en el set de entrenamiento

logistic_model = logistic.fit(x_train_res, y_train_res)
# Preparar función de resultados

def display_test_results(model_name, model):
    
    # Prediction on the test set
    y_test_pred = model.predict(X_test)
    
    # Confusion matrix
    print("------------------ Confusion Matrix --------------------")
    c_matrix = metrics.confusion_matrix(y_test, y_test_pred)
    print(c_matrix)
    
    cm_display = ConfusionMatrixDisplay(confusion_matrix=c_matrix)
    cm_display.plot(cmap=plt.cm.Blues)
    plt.show()
    

    # classification_report
    print("------------------ classification_report --------------------")
    print(classification_report(y_test, y_test_pred))
    
    print("------------------ More Specific classification_report --------------------")
    TP = c_matrix[1,1] # true positive 
    TN = c_matrix[0,0] # true negatives
    FP = c_matrix[0,1] # false positives
    FN = c_matrix[1,0] # false negatives

    # Accuracy
    print("Accuracy:-",metrics.accuracy_score(y_test, y_test_pred))

    # Sensitivity
    print("Sensitivity:-",TP / float(TP+FN))

    # Specificity
    print("Specificity:-", TN / float(TN+FP))

    # F1 score
    print("F1-Score:-", f1_score(y_test, y_test_pred))

    # Predicted probability
    y_test_pred_proba = model.predict_proba(X_test)[:,1]

    # roc_auc
    print("------------------ ROC --------------------")
    roc_auc = metrics.roc_auc_score(y_test, y_test_pred_proba)

    # Plot the ROC curve
    draw_roc(y_test, y_test_pred_proba)

    # add all metrics score in final result store
    results.loc[len(results)] = [model_name, metrics.accuracy_score(y_test, y_test_pred), f1_score(y_test, y_test_pred), roc_auc]

    return None

4.1.1. Resultados de predicción Modelo de Regresión Logística

display_test_results("Logistic Regression", logistic_model)
## ------------------ Confusion Matrix --------------------
## [[3042    0]
##  [ 121    0]]
## ------------------ classification_report --------------------
##               precision    recall  f1-score   support
## 
##            0       0.96      1.00      0.98      3042
##            1       0.00      0.00      0.00       121
## 
##     accuracy                           0.96      3163
##    macro avg       0.48      0.50      0.49      3163
## weighted avg       0.92      0.96      0.94      3163
## 
## ------------------ More Specific classification_report --------------------
## Accuracy:- 0.9617451786278849
## Sensitivity:- 0.0
## Specificity:- 1.0
## F1-Score:- 0.0
## ------------------ ROC --------------------

4.2. Modelo XGBoost

# Importamos  XGBoost

from xgboost import XGBClassifier
params = {'learning_rate': 0.2,
          'max_depth': 2, 
          'n_estimators':200,
          'subsample':0.9,
         'objective':'binary:logistic'}
# modelo de ajuste en datos de entrenamiento

xgb_model = XGBClassifier(params = params)
xgb_model.fit(x_train_res, y_train_res)
## [18:50:17] WARNING: C:/Users/administrator/workspace/xgboost-win64_release_1.6.0/src/learner.cc:627: 
## Parameters: { "params" } might not be used.
## 
##   This could be a false alarm, with some parameters getting used by language bindings but
##   then being mistakenly passed down to XGBoost core, or some parameter actually being used
##   but getting flagged wrongly here. Please open an issue if you find any such cases.
## 
## 
## XGBClassifier(base_score=0.5, booster='gbtree', callbacks=None,
##               colsample_bylevel=1, colsample_bynode=1, colsample_bytree=1,
##               early_stopping_rounds=None, enable_categorical=False,
##               eval_metric=None, gamma=0, gpu_id=-1, grow_policy='depthwise',
##               importance_type=None, interaction_constraints='',
##               learning_rate=0.300000012, max_bin=256, max_cat_to_onehot=4,
##               max_delta_step=0, max_depth=6, max_leaves=0, min_child_weight=1,
##               missing=nan, monotone_constraints='()', n_estimators=100,
##               n_jobs=0, num_parallel_tree=1,
##               params={'learning_rate': 0.2, 'max_depth': 2, 'n_estimators': 200,
##                       'objective': 'binary:logistic', 'subsample': 0.9},
##               predictor='auto', random_state=0, reg_alpha=0, ...)

4.2.1. Resultados de predicción Modelo XGBoost

display_test_results("XG Boost", xgb_model)
## ------------------ Confusion Matrix --------------------
## [[2819  223]
##  [ 101   20]]
## ------------------ classification_report --------------------
##               precision    recall  f1-score   support
## 
##            0       0.97      0.93      0.95      3042
##            1       0.08      0.17      0.11       121
## 
##     accuracy                           0.90      3163
##    macro avg       0.52      0.55      0.53      3163
## weighted avg       0.93      0.90      0.91      3163
## 
## ------------------ More Specific classification_report --------------------
## Accuracy:- 0.89756560227632
## Sensitivity:- 0.1652892561983471
## Specificity:- 0.9266929651545036
## F1-Score:- 0.10989010989010989
## ------------------ ROC --------------------

4.3. Modelo Árbol de decisión

# Importando clasificador del árbol de decisión

from sklearn.tree import DecisionTreeClassifier
# Modelo con hiperparámetros óptimos

decision_tree_model = DecisionTreeClassifier(criterion = "gini", 
                                  random_state = 100,
                                  max_depth=5, 
                                  min_samples_leaf=100,
                                  min_samples_split=100)

decision_tree_model.fit(x_train_res, y_train_res)
## DecisionTreeClassifier(max_depth=5, min_samples_leaf=100, min_samples_split=100,
##                        random_state=100)

4.3.1. Resultados de predicción Modelo Árbol de decisión

display_test_results("Decision Tree", decision_tree_model)
## ------------------ Confusion Matrix --------------------
## [[2550  492]
##  [  82   39]]
## ------------------ classification_report --------------------
##               precision    recall  f1-score   support
## 
##            0       0.97      0.84      0.90      3042
##            1       0.07      0.32      0.12       121
## 
##     accuracy                           0.82      3163
##    macro avg       0.52      0.58      0.51      3163
## weighted avg       0.93      0.82      0.87      3163
## 
## ------------------ More Specific classification_report --------------------
## Accuracy:- 0.8185267151438508
## Sensitivity:- 0.32231404958677684
## Specificity:- 0.8382642998027613
## F1-Score:- 0.1196319018404908
## ------------------ ROC --------------------

4.4. Modelo Bosque aleatorio

# Importando clasificador de bosque aleatorio

from sklearn.ensemble import RandomForestClassifier
random_forest_model = RandomForestClassifier(bootstrap=True,
                             max_depth=5,
                             min_samples_leaf=50, 
                             min_samples_split=50,
                             max_features=10,
                             n_estimators=100)
# Ajustar el modelo

random_forest_model.fit(x_train_res, y_train_res)
## RandomForestClassifier(max_depth=5, max_features=10, min_samples_leaf=50,
##                        min_samples_split=50)

4.4.1. Resultados de predicción Modelo Bosque aleatorio

display_test_results("Random Forest", random_forest_model)
## ------------------ Confusion Matrix --------------------
## [[2411  631]
##  [  78   43]]
## ------------------ classification_report --------------------
##               precision    recall  f1-score   support
## 
##            0       0.97      0.79      0.87      3042
##            1       0.06      0.36      0.11       121
## 
##     accuracy                           0.78      3163
##    macro avg       0.52      0.57      0.49      3163
## weighted avg       0.93      0.78      0.84      3163
## 
## ------------------ More Specific classification_report --------------------
## Accuracy:- 0.7758457160923175
## Sensitivity:- 0.35537190082644626
## Specificity:- 0.7925706771860618
## F1-Score:- 0.10817610062893081
## ------------------ ROC --------------------

5. Resumen

results.sort_values(by="ROC", ascending=False)
##             Model Name  Accuracy  F1-score       ROC
## 1             XG Boost  0.897566  0.109890  0.649472
## 3        Random Forest  0.775846  0.108176  0.620794
## 2        Decision Tree  0.818527  0.119632  0.608542
## 0  Logistic Regression  0.961745  0.000000  0.561807