LASSO Regression using Package caret

Data Mining

Description for LASSO Regression using Package caret

Yeongeun Jeon , Jung In Seo
2023-08-13

LASSO Regression의 장점


LASSO Regression의 단점


실습 자료 : 유니버셜 은행의 고객 2,500명에 대한 자료(출처 : Data Mining for Business Intelligence, Shmueli et al. 2010)이며, 총 13개의 변수를 포함하고 있다. 이 자료에서 TargetPersonal Loan이다.




Contents


1. 데이터 불러오기

pacman::p_load("data.table", 
               "tidyverse", 
               "dplyr",
               "ggplot2", "GGally",
               "caret",
               "doParallel", "parallel")                                # For 병렬 처리

registerDoParallel(cores=detectCores())                                 # 사용할 Core 개수 지정     

UB <- fread("../Universal Bank_Main.csv")                               # 데이터 불러오기

UB %>%
  as_tibble
# A tibble: 2,500 × 14
      ID   Age Experience Income `ZIP Code` Family CCAvg Education
   <int> <int>      <int>  <int>      <int>  <int> <dbl>     <int>
 1     1    25          1     49      91107      4   1.6         1
 2     2    45         19     34      90089      3   1.5         1
 3     3    39         15     11      94720      1   1           1
 4     4    35          9    100      94112      1   2.7         2
 5     5    35          8     45      91330      4   1           2
 6     6    37         13     29      92121      4   0.4         2
 7     7    53         27     72      91711      2   1.5         2
 8     8    50         24     22      93943      1   0.3         3
 9     9    35         10     81      90089      3   0.6         2
10    10    34          9    180      93023      1   8.9         3
# ℹ 2,490 more rows
# ℹ 6 more variables: Mortgage <int>, `Personal Loan` <int>,
#   `Securities Account` <int>, `CD Account` <int>, Online <int>,
#   CreditCard <int>

2. 데이터 전처리

UB %<>%
  data.frame() %>%                                                      # Data Frame 형태로 변환 
  mutate(Personal.Loan = ifelse(Personal.Loan == 1, "yes", "no")) %>%   # Target을 문자형 변수로 변환
  select(-1)                                                            # ID 변수 제거

# Convert to Factor
fac.col <- c("Family", "Education", "Securities.Account", 
             "CD.Account", "Online", "CreditCard",
             # Target
             "Personal.Loan")

UB <- UB %>% 
  mutate_at(fac.col, as.factor)                                         # 범주형으로 변환

glimpse(UB)                                                             # 데이터 구조 확인
Rows: 2,500
Columns: 13
$ Age                <int> 25, 45, 39, 35, 35, 37, 53, 50, 35, 34, 6…
$ Experience         <int> 1, 19, 15, 9, 8, 13, 27, 24, 10, 9, 39, 5…
$ Income             <int> 49, 34, 11, 100, 45, 29, 72, 22, 81, 180,…
$ ZIP.Code           <int> 91107, 90089, 94720, 94112, 91330, 92121,…
$ Family             <fct> 4, 3, 1, 1, 4, 4, 2, 1, 3, 1, 4, 3, 2, 4,…
$ CCAvg              <dbl> 1.6, 1.5, 1.0, 2.7, 1.0, 0.4, 1.5, 0.3, 0…
$ Education          <fct> 1, 1, 1, 2, 2, 2, 2, 3, 2, 3, 3, 2, 3, 2,…
$ Mortgage           <int> 0, 0, 0, 0, 0, 155, 0, 0, 104, 0, 0, 0, 0…
$ Personal.Loan      <fct> no, no, no, no, no, no, no, no, no, yes, …
$ Securities.Account <fct> 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,…
$ CD.Account         <fct> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ Online             <fct> 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1,…
$ CreditCard         <fct> 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,…

3. 데이터 탐색

ggpairs(UB,                                             
        columns = c("Age", "Experience", "Income",        # 수치형 예측 변수
                    "ZIP.Code", "CCAvg", "Mortgage"),                            
        aes(colour = Personal.Loan)) +                    # Target의 범주에 따라 색깔을 다르게 표현
  theme_bw()  
ggpairs(UB,                                          
        columns = c("Age", "Experience", "Income",        # 수치형 예측 변수
                    "ZIP.Code", "CCAvg", "Mortgage"), 
        aes(colour = Personal.Loan)) +                    # Target의 범주에 따라 색깔을 다르게 표현
  scale_color_brewer(palette="Purples") +                 # 특정 색깔 지정
  scale_fill_brewer(palette="Purples") +                  # 특정 색깔 지정
  theme_bw()
ggpairs(UB,                                        
        columns = c("Age", "Income",                      # 수치형 예측 변수
                    "Family", "Education"),               # 범주형 예측 변수
        aes(colour = Personal.Loan, alpha = 0.8)) +       # Target의 범주에 따라 색깔을 다르게 표현
  scale_colour_manual(values = c("purple","cyan4")) +     # 특정 색깔 지정
  scale_fill_manual(values = c("purple","cyan4")) +       # 특정 색깔 지정
  theme_bw()


4. 데이터 분할

# Partition (Training Dataset : Test Dataset = 7:3)
y      <- UB$Personal.Loan                            # Target
 
set.seed(200)
ind    <- createDataPartition(y, p = 0.7, list = T)   # Index를 이용하여 7:3으로 분할
UB.trd <- UB[ind$Resample1,]                          # Training Dataset
UB.ted <- UB[-ind$Resample1,]                         # Test Dataset

5. 모형 훈련

Package "caret"은 통합 API를 통해 R로 기계 학습을 실행할 수 있는 매우 실용적인 방법을 제공한다. Package "caret"를 통해 LASSO Regression을 수행하기 위해 옵션 method에 다양한 방법(Ex: "lasso", "blasso" 등)을 입력할 수 있지만, 대부분 회귀 문제에 대해서만 분석이 가능하다. 분류와 회귀 문제 모두 가능한 "glmnet"을 이용하려면 옵션 tuneGrid = expand.grid()을 통해 탐색하고자 하는 초모수 lambda의 범위를 직접 지정해줘야 한다.

fitControl <- trainControl(method = "cv", number = 5,                 # 5-Fold Cross Validation (5-Fold CV)
                           allowParallel = TRUE)                      # 병렬 처리


set.seed(200)                                                         # For CV
lasso.fit <- train(Personal.Loan ~ ., data = UB.trd, 
                   trControl = fitControl ,
                   method = "glmnet",
                   tuneGrid = expand.grid(alpha = 1,                  # For LASSO Regression
                                          lambda = seq(0, 1, 0.001)), # lambda의 탐색 범위
                   preProc = c("center", "scale"))                    # Standardization for 예측 변수

lasso.fit
glmnet 

1751 samples
  12 predictor
   2 classes: 'no', 'yes' 

Pre-processing: centered (15), scaled (15) 
Resampling: Cross-Validated (5 fold) 
Summary of sample sizes: 1401, 1401, 1400, 1401, 1401 
Resampling results across tuning parameters:

  lambda  Accuracy   Kappa      
  0.000   0.9583053  0.751538993
  0.001   0.9588767  0.752418331
  0.002   0.9577354  0.743256100
  0.003   0.9577354  0.742059920
  0.004   0.9565926  0.733576889
  0.005   0.9554514  0.726784857
  0.006   0.9537387  0.712729772
  0.007   0.9525958  0.702796871
  0.008   0.9520244  0.697985312
  0.009   0.9508816  0.688763877
  0.010   0.9508816  0.688763877
  0.011   0.9508816  0.688763877
  0.012   0.9497387  0.679863757
  0.013   0.9485958  0.670694570
  0.014   0.9480260  0.665771867
  0.015   0.9468832  0.656213995
  0.016   0.9445975  0.636317627
  0.017   0.9423134  0.619546346
  0.018   0.9405991  0.606507131
  0.019   0.9388848  0.590199261
  0.020   0.9388848  0.590199261
  0.021   0.9348848  0.559149435
  0.022   0.9326007  0.538520693
  0.023   0.9303183  0.523144315
  0.024   0.9297501  0.519451170
  0.025   0.9286072  0.512038401
  0.026   0.9268930  0.498501525
  0.027   0.9234693  0.465556693
  0.028   0.9223264  0.454010402
  0.029   0.9206138  0.436027387
  0.030   0.9177582  0.406751134
  0.031   0.9166170  0.393810038
  0.032   0.9154758  0.382031101
  0.033   0.9137615  0.363984391
  0.034   0.9137615  0.363984391
  0.035   0.9131884  0.352590508
  0.036   0.9120456  0.338919927
  0.037   0.9109027  0.326146558
  0.038   0.9114742  0.324129628
  0.039   0.9120456  0.325911450
  0.040   0.9114725  0.309687237
  0.041   0.9114725  0.303349935
  0.042   0.9120440  0.305407784
  0.043   0.9120440  0.299376432
  0.044   0.9103297  0.278130229
  0.045   0.9091868  0.264416018
  0.046   0.9080440  0.249521822
  0.047   0.9091868  0.252591102
  0.048   0.9103280  0.256503169
  0.049   0.9108995  0.258127513
  0.050   0.9114693  0.255106230
  0.051   0.9103297  0.241720391
  0.052   0.9097582  0.234020160
  0.053   0.9097582  0.228119255
  0.054   0.9097599  0.216427058
  0.055   0.9074758  0.184019046
  0.056   0.9080472  0.185486079
  0.057   0.9074758  0.177033425
  0.058   0.9080472  0.178917305
  0.059   0.9074774  0.171290986
  0.060   0.9080488  0.172909816
  0.061   0.9080488  0.172909816
  0.062   0.9074774  0.164660050
  0.063   0.9063346  0.147114559
  0.064   0.9051933  0.129844066
  0.065   0.9046235  0.121592703
  0.066   0.9040537  0.112999601
  0.067   0.9040537  0.112999601
  0.068   0.9029109  0.093905651
  0.069   0.9023394  0.084152584
  0.070   0.9017680  0.075198298
  0.071   0.9011982  0.066241776
  0.072   0.9011982  0.066241776
  0.073   0.9011982  0.066241776
  0.074   0.9006268  0.057287490
  0.075   0.8994872  0.038187899
  0.076   0.8994872  0.038187899
  0.077   0.8983443  0.019093950
  0.078   0.8977729  0.009753067
  0.079   0.8972015  0.000000000
  0.080   0.8972015  0.000000000
  0.081   0.8972015  0.000000000
  0.082   0.8972015  0.000000000
  0.083   0.8972015  0.000000000
  0.084   0.8972015  0.000000000
  0.085   0.8972015  0.000000000
  0.086   0.8972015  0.000000000
  0.087   0.8972015  0.000000000
  0.088   0.8972015  0.000000000
  0.089   0.8972015  0.000000000
  0.090   0.8972015  0.000000000
  0.091   0.8972015  0.000000000
  0.092   0.8972015  0.000000000
  0.093   0.8972015  0.000000000
  0.094   0.8972015  0.000000000
  0.095   0.8972015  0.000000000
  0.096   0.8972015  0.000000000
  0.097   0.8972015  0.000000000
  0.098   0.8972015  0.000000000
  0.099   0.8972015  0.000000000
  0.100   0.8972015  0.000000000
  0.101   0.8972015  0.000000000
  0.102   0.8972015  0.000000000
  0.103   0.8972015  0.000000000
  0.104   0.8972015  0.000000000
  0.105   0.8972015  0.000000000
  0.106   0.8972015  0.000000000
  0.107   0.8972015  0.000000000
  0.108   0.8972015  0.000000000
  0.109   0.8972015  0.000000000
  0.110   0.8972015  0.000000000
  0.111   0.8972015  0.000000000
  0.112   0.8972015  0.000000000
  0.113   0.8972015  0.000000000
  0.114   0.8972015  0.000000000
  0.115   0.8972015  0.000000000
  0.116   0.8972015  0.000000000
  0.117   0.8972015  0.000000000
  0.118   0.8972015  0.000000000
  0.119   0.8972015  0.000000000
  0.120   0.8972015  0.000000000
  0.121   0.8972015  0.000000000
  0.122   0.8972015  0.000000000
  0.123   0.8972015  0.000000000
  0.124   0.8972015  0.000000000
  0.125   0.8972015  0.000000000
  0.126   0.8972015  0.000000000
  0.127   0.8972015  0.000000000
  0.128   0.8972015  0.000000000
  0.129   0.8972015  0.000000000
  0.130   0.8972015  0.000000000
  0.131   0.8972015  0.000000000
  0.132   0.8972015  0.000000000
  0.133   0.8972015  0.000000000
  0.134   0.8972015  0.000000000
  0.135   0.8972015  0.000000000
  0.136   0.8972015  0.000000000
  0.137   0.8972015  0.000000000
  0.138   0.8972015  0.000000000
  0.139   0.8972015  0.000000000
  0.140   0.8972015  0.000000000
  0.141   0.8972015  0.000000000
  0.142   0.8972015  0.000000000
  0.143   0.8972015  0.000000000
  0.144   0.8972015  0.000000000
  0.145   0.8972015  0.000000000
  0.146   0.8972015  0.000000000
  0.147   0.8972015  0.000000000
  0.148   0.8972015  0.000000000
  0.149   0.8972015  0.000000000
  0.150   0.8972015  0.000000000
  0.151   0.8972015  0.000000000
  0.152   0.8972015  0.000000000
  0.153   0.8972015  0.000000000
  0.154   0.8972015  0.000000000
  0.155   0.8972015  0.000000000
  0.156   0.8972015  0.000000000
  0.157   0.8972015  0.000000000
  0.158   0.8972015  0.000000000
  0.159   0.8972015  0.000000000
  0.160   0.8972015  0.000000000
  0.161   0.8972015  0.000000000
  0.162   0.8972015  0.000000000
  0.163   0.8972015  0.000000000
  0.164   0.8972015  0.000000000
  0.165   0.8972015  0.000000000
  0.166   0.8972015  0.000000000
  0.167   0.8972015  0.000000000
  0.168   0.8972015  0.000000000
  0.169   0.8972015  0.000000000
  0.170   0.8972015  0.000000000
  0.171   0.8972015  0.000000000
  0.172   0.8972015  0.000000000
  0.173   0.8972015  0.000000000
  0.174   0.8972015  0.000000000
  0.175   0.8972015  0.000000000
  0.176   0.8972015  0.000000000
  0.177   0.8972015  0.000000000
  0.178   0.8972015  0.000000000
  0.179   0.8972015  0.000000000
  0.180   0.8972015  0.000000000
  0.181   0.8972015  0.000000000
  0.182   0.8972015  0.000000000
  0.183   0.8972015  0.000000000
  0.184   0.8972015  0.000000000
  0.185   0.8972015  0.000000000
  0.186   0.8972015  0.000000000
  0.187   0.8972015  0.000000000
  0.188   0.8972015  0.000000000
  0.189   0.8972015  0.000000000
  0.190   0.8972015  0.000000000
  0.191   0.8972015  0.000000000
  0.192   0.8972015  0.000000000
  0.193   0.8972015  0.000000000
  0.194   0.8972015  0.000000000
  0.195   0.8972015  0.000000000
  0.196   0.8972015  0.000000000
  0.197   0.8972015  0.000000000
  0.198   0.8972015  0.000000000
  0.199   0.8972015  0.000000000
  0.200   0.8972015  0.000000000
  0.201   0.8972015  0.000000000
  0.202   0.8972015  0.000000000
  0.203   0.8972015  0.000000000
  0.204   0.8972015  0.000000000
  0.205   0.8972015  0.000000000
  0.206   0.8972015  0.000000000
  0.207   0.8972015  0.000000000
  0.208   0.8972015  0.000000000
  0.209   0.8972015  0.000000000
  0.210   0.8972015  0.000000000
  0.211   0.8972015  0.000000000
  0.212   0.8972015  0.000000000
  0.213   0.8972015  0.000000000
  0.214   0.8972015  0.000000000
  0.215   0.8972015  0.000000000
  0.216   0.8972015  0.000000000
  0.217   0.8972015  0.000000000
  0.218   0.8972015  0.000000000
  0.219   0.8972015  0.000000000
  0.220   0.8972015  0.000000000
  0.221   0.8972015  0.000000000
  0.222   0.8972015  0.000000000
  0.223   0.8972015  0.000000000
  0.224   0.8972015  0.000000000
  0.225   0.8972015  0.000000000
  0.226   0.8972015  0.000000000
  0.227   0.8972015  0.000000000
  0.228   0.8972015  0.000000000
  0.229   0.8972015  0.000000000
  0.230   0.8972015  0.000000000
  0.231   0.8972015  0.000000000
  0.232   0.8972015  0.000000000
  0.233   0.8972015  0.000000000
  0.234   0.8972015  0.000000000
  0.235   0.8972015  0.000000000
  0.236   0.8972015  0.000000000
  0.237   0.8972015  0.000000000
  0.238   0.8972015  0.000000000
  0.239   0.8972015  0.000000000
  0.240   0.8972015  0.000000000
  0.241   0.8972015  0.000000000
  0.242   0.8972015  0.000000000
  0.243   0.8972015  0.000000000
  0.244   0.8972015  0.000000000
  0.245   0.8972015  0.000000000
  0.246   0.8972015  0.000000000
  0.247   0.8972015  0.000000000
  0.248   0.8972015  0.000000000
  0.249   0.8972015  0.000000000
  0.250   0.8972015  0.000000000
  0.251   0.8972015  0.000000000
  0.252   0.8972015  0.000000000
  0.253   0.8972015  0.000000000
  0.254   0.8972015  0.000000000
  0.255   0.8972015  0.000000000
  0.256   0.8972015  0.000000000
  0.257   0.8972015  0.000000000
  0.258   0.8972015  0.000000000
  0.259   0.8972015  0.000000000
  0.260   0.8972015  0.000000000
  0.261   0.8972015  0.000000000
  0.262   0.8972015  0.000000000
  0.263   0.8972015  0.000000000
  0.264   0.8972015  0.000000000
  0.265   0.8972015  0.000000000
  0.266   0.8972015  0.000000000
  0.267   0.8972015  0.000000000
  0.268   0.8972015  0.000000000
  0.269   0.8972015  0.000000000
  0.270   0.8972015  0.000000000
  0.271   0.8972015  0.000000000
  0.272   0.8972015  0.000000000
  0.273   0.8972015  0.000000000
  0.274   0.8972015  0.000000000
  0.275   0.8972015  0.000000000
  0.276   0.8972015  0.000000000
  0.277   0.8972015  0.000000000
  0.278   0.8972015  0.000000000
  0.279   0.8972015  0.000000000
  0.280   0.8972015  0.000000000
  0.281   0.8972015  0.000000000
  0.282   0.8972015  0.000000000
  0.283   0.8972015  0.000000000
  0.284   0.8972015  0.000000000
  0.285   0.8972015  0.000000000
  0.286   0.8972015  0.000000000
  0.287   0.8972015  0.000000000
  0.288   0.8972015  0.000000000
  0.289   0.8972015  0.000000000
  0.290   0.8972015  0.000000000
  0.291   0.8972015  0.000000000
  0.292   0.8972015  0.000000000
  0.293   0.8972015  0.000000000
  0.294   0.8972015  0.000000000
  0.295   0.8972015  0.000000000
  0.296   0.8972015  0.000000000
  0.297   0.8972015  0.000000000
  0.298   0.8972015  0.000000000
  0.299   0.8972015  0.000000000
  0.300   0.8972015  0.000000000
  0.301   0.8972015  0.000000000
  0.302   0.8972015  0.000000000
  0.303   0.8972015  0.000000000
  0.304   0.8972015  0.000000000
  0.305   0.8972015  0.000000000
  0.306   0.8972015  0.000000000
  0.307   0.8972015  0.000000000
  0.308   0.8972015  0.000000000
  0.309   0.8972015  0.000000000
  0.310   0.8972015  0.000000000
  0.311   0.8972015  0.000000000
  0.312   0.8972015  0.000000000
  0.313   0.8972015  0.000000000
  0.314   0.8972015  0.000000000
  0.315   0.8972015  0.000000000
  0.316   0.8972015  0.000000000
  0.317   0.8972015  0.000000000
  0.318   0.8972015  0.000000000
  0.319   0.8972015  0.000000000
  0.320   0.8972015  0.000000000
  0.321   0.8972015  0.000000000
  0.322   0.8972015  0.000000000
  0.323   0.8972015  0.000000000
  0.324   0.8972015  0.000000000
  0.325   0.8972015  0.000000000
  0.326   0.8972015  0.000000000
  0.327   0.8972015  0.000000000
  0.328   0.8972015  0.000000000
  0.329   0.8972015  0.000000000
  0.330   0.8972015  0.000000000
  0.331   0.8972015  0.000000000
  0.332   0.8972015  0.000000000
  0.333   0.8972015  0.000000000
  0.334   0.8972015  0.000000000
  0.335   0.8972015  0.000000000
  0.336   0.8972015  0.000000000
  0.337   0.8972015  0.000000000
  0.338   0.8972015  0.000000000
  0.339   0.8972015  0.000000000
  0.340   0.8972015  0.000000000
  0.341   0.8972015  0.000000000
  0.342   0.8972015  0.000000000
  0.343   0.8972015  0.000000000
  0.344   0.8972015  0.000000000
  0.345   0.8972015  0.000000000
  0.346   0.8972015  0.000000000
  0.347   0.8972015  0.000000000
  0.348   0.8972015  0.000000000
  0.349   0.8972015  0.000000000
  0.350   0.8972015  0.000000000
  0.351   0.8972015  0.000000000
  0.352   0.8972015  0.000000000
  0.353   0.8972015  0.000000000
  0.354   0.8972015  0.000000000
  0.355   0.8972015  0.000000000
  0.356   0.8972015  0.000000000
  0.357   0.8972015  0.000000000
  0.358   0.8972015  0.000000000
  0.359   0.8972015  0.000000000
  0.360   0.8972015  0.000000000
  0.361   0.8972015  0.000000000
  0.362   0.8972015  0.000000000
  0.363   0.8972015  0.000000000
  0.364   0.8972015  0.000000000
  0.365   0.8972015  0.000000000
  0.366   0.8972015  0.000000000
  0.367   0.8972015  0.000000000
  0.368   0.8972015  0.000000000
  0.369   0.8972015  0.000000000
  0.370   0.8972015  0.000000000
  0.371   0.8972015  0.000000000
  0.372   0.8972015  0.000000000
  0.373   0.8972015  0.000000000
  0.374   0.8972015  0.000000000
  0.375   0.8972015  0.000000000
  0.376   0.8972015  0.000000000
  0.377   0.8972015  0.000000000
  0.378   0.8972015  0.000000000
  0.379   0.8972015  0.000000000
  0.380   0.8972015  0.000000000
  0.381   0.8972015  0.000000000
  0.382   0.8972015  0.000000000
  0.383   0.8972015  0.000000000
  0.384   0.8972015  0.000000000
  0.385   0.8972015  0.000000000
  0.386   0.8972015  0.000000000
  0.387   0.8972015  0.000000000
  0.388   0.8972015  0.000000000
  0.389   0.8972015  0.000000000
  0.390   0.8972015  0.000000000
  0.391   0.8972015  0.000000000
  0.392   0.8972015  0.000000000
  0.393   0.8972015  0.000000000
  0.394   0.8972015  0.000000000
  0.395   0.8972015  0.000000000
  0.396   0.8972015  0.000000000
  0.397   0.8972015  0.000000000
  0.398   0.8972015  0.000000000
  0.399   0.8972015  0.000000000
  0.400   0.8972015  0.000000000
  0.401   0.8972015  0.000000000
  0.402   0.8972015  0.000000000
  0.403   0.8972015  0.000000000
  0.404   0.8972015  0.000000000
  0.405   0.8972015  0.000000000
  0.406   0.8972015  0.000000000
  0.407   0.8972015  0.000000000
  0.408   0.8972015  0.000000000
  0.409   0.8972015  0.000000000
  0.410   0.8972015  0.000000000
  0.411   0.8972015  0.000000000
  0.412   0.8972015  0.000000000
  0.413   0.8972015  0.000000000
  0.414   0.8972015  0.000000000
  0.415   0.8972015  0.000000000
  0.416   0.8972015  0.000000000
  0.417   0.8972015  0.000000000
  0.418   0.8972015  0.000000000
  0.419   0.8972015  0.000000000
  0.420   0.8972015  0.000000000
  0.421   0.8972015  0.000000000
  0.422   0.8972015  0.000000000
  0.423   0.8972015  0.000000000
  0.424   0.8972015  0.000000000
  0.425   0.8972015  0.000000000
  0.426   0.8972015  0.000000000
  0.427   0.8972015  0.000000000
  0.428   0.8972015  0.000000000
  0.429   0.8972015  0.000000000
  0.430   0.8972015  0.000000000
  0.431   0.8972015  0.000000000
  0.432   0.8972015  0.000000000
  0.433   0.8972015  0.000000000
  0.434   0.8972015  0.000000000
  0.435   0.8972015  0.000000000
  0.436   0.8972015  0.000000000
  0.437   0.8972015  0.000000000
  0.438   0.8972015  0.000000000
  0.439   0.8972015  0.000000000
  0.440   0.8972015  0.000000000
  0.441   0.8972015  0.000000000
  0.442   0.8972015  0.000000000
  0.443   0.8972015  0.000000000
  0.444   0.8972015  0.000000000
  0.445   0.8972015  0.000000000
  0.446   0.8972015  0.000000000
  0.447   0.8972015  0.000000000
  0.448   0.8972015  0.000000000
  0.449   0.8972015  0.000000000
  0.450   0.8972015  0.000000000
  0.451   0.8972015  0.000000000
  0.452   0.8972015  0.000000000
  0.453   0.8972015  0.000000000
  0.454   0.8972015  0.000000000
  0.455   0.8972015  0.000000000
  0.456   0.8972015  0.000000000
  0.457   0.8972015  0.000000000
  0.458   0.8972015  0.000000000
  0.459   0.8972015  0.000000000
  0.460   0.8972015  0.000000000
  0.461   0.8972015  0.000000000
  0.462   0.8972015  0.000000000
  0.463   0.8972015  0.000000000
  0.464   0.8972015  0.000000000
  0.465   0.8972015  0.000000000
  0.466   0.8972015  0.000000000
  0.467   0.8972015  0.000000000
  0.468   0.8972015  0.000000000
  0.469   0.8972015  0.000000000
  0.470   0.8972015  0.000000000
  0.471   0.8972015  0.000000000
  0.472   0.8972015  0.000000000
  0.473   0.8972015  0.000000000
  0.474   0.8972015  0.000000000
  0.475   0.8972015  0.000000000
  0.476   0.8972015  0.000000000
  0.477   0.8972015  0.000000000
  0.478   0.8972015  0.000000000
  0.479   0.8972015  0.000000000
  0.480   0.8972015  0.000000000
  0.481   0.8972015  0.000000000
  0.482   0.8972015  0.000000000
  0.483   0.8972015  0.000000000
  0.484   0.8972015  0.000000000
  0.485   0.8972015  0.000000000
  0.486   0.8972015  0.000000000
  0.487   0.8972015  0.000000000
  0.488   0.8972015  0.000000000
  0.489   0.8972015  0.000000000
  0.490   0.8972015  0.000000000
  0.491   0.8972015  0.000000000
  0.492   0.8972015  0.000000000
  0.493   0.8972015  0.000000000
  0.494   0.8972015  0.000000000
  0.495   0.8972015  0.000000000
  0.496   0.8972015  0.000000000
  0.497   0.8972015  0.000000000
  0.498   0.8972015  0.000000000
  0.499   0.8972015  0.000000000
  0.500   0.8972015  0.000000000
  0.501   0.8972015  0.000000000
  0.502   0.8972015  0.000000000
  0.503   0.8972015  0.000000000
  0.504   0.8972015  0.000000000
  0.505   0.8972015  0.000000000
  0.506   0.8972015  0.000000000
  0.507   0.8972015  0.000000000
  0.508   0.8972015  0.000000000
  0.509   0.8972015  0.000000000
  0.510   0.8972015  0.000000000
  0.511   0.8972015  0.000000000
  0.512   0.8972015  0.000000000
  0.513   0.8972015  0.000000000
  0.514   0.8972015  0.000000000
  0.515   0.8972015  0.000000000
  0.516   0.8972015  0.000000000
  0.517   0.8972015  0.000000000
  0.518   0.8972015  0.000000000
  0.519   0.8972015  0.000000000
  0.520   0.8972015  0.000000000
  0.521   0.8972015  0.000000000
  0.522   0.8972015  0.000000000
  0.523   0.8972015  0.000000000
  0.524   0.8972015  0.000000000
  0.525   0.8972015  0.000000000
  0.526   0.8972015  0.000000000
  0.527   0.8972015  0.000000000
  0.528   0.8972015  0.000000000
  0.529   0.8972015  0.000000000
  0.530   0.8972015  0.000000000
  0.531   0.8972015  0.000000000
  0.532   0.8972015  0.000000000
  0.533   0.8972015  0.000000000
  0.534   0.8972015  0.000000000
  0.535   0.8972015  0.000000000
  0.536   0.8972015  0.000000000
  0.537   0.8972015  0.000000000
  0.538   0.8972015  0.000000000
  0.539   0.8972015  0.000000000
  0.540   0.8972015  0.000000000
  0.541   0.8972015  0.000000000
  0.542   0.8972015  0.000000000
  0.543   0.8972015  0.000000000
  0.544   0.8972015  0.000000000
  0.545   0.8972015  0.000000000
  0.546   0.8972015  0.000000000
  0.547   0.8972015  0.000000000
  0.548   0.8972015  0.000000000
  0.549   0.8972015  0.000000000
  0.550   0.8972015  0.000000000
  0.551   0.8972015  0.000000000
  0.552   0.8972015  0.000000000
  0.553   0.8972015  0.000000000
  0.554   0.8972015  0.000000000
  0.555   0.8972015  0.000000000
  0.556   0.8972015  0.000000000
  0.557   0.8972015  0.000000000
  0.558   0.8972015  0.000000000
  0.559   0.8972015  0.000000000
  0.560   0.8972015  0.000000000
  0.561   0.8972015  0.000000000
  0.562   0.8972015  0.000000000
  0.563   0.8972015  0.000000000
  0.564   0.8972015  0.000000000
  0.565   0.8972015  0.000000000
  0.566   0.8972015  0.000000000
  0.567   0.8972015  0.000000000
  0.568   0.8972015  0.000000000
  0.569   0.8972015  0.000000000
  0.570   0.8972015  0.000000000
  0.571   0.8972015  0.000000000
  0.572   0.8972015  0.000000000
  0.573   0.8972015  0.000000000
  0.574   0.8972015  0.000000000
  0.575   0.8972015  0.000000000
  0.576   0.8972015  0.000000000
  0.577   0.8972015  0.000000000
  0.578   0.8972015  0.000000000
  0.579   0.8972015  0.000000000
  0.580   0.8972015  0.000000000
  0.581   0.8972015  0.000000000
  0.582   0.8972015  0.000000000
  0.583   0.8972015  0.000000000
  0.584   0.8972015  0.000000000
  0.585   0.8972015  0.000000000
  0.586   0.8972015  0.000000000
  0.587   0.8972015  0.000000000
  0.588   0.8972015  0.000000000
  0.589   0.8972015  0.000000000
  0.590   0.8972015  0.000000000
  0.591   0.8972015  0.000000000
  0.592   0.8972015  0.000000000
  0.593   0.8972015  0.000000000
  0.594   0.8972015  0.000000000
  0.595   0.8972015  0.000000000
  0.596   0.8972015  0.000000000
  0.597   0.8972015  0.000000000
  0.598   0.8972015  0.000000000
  0.599   0.8972015  0.000000000
  0.600   0.8972015  0.000000000
  0.601   0.8972015  0.000000000
  0.602   0.8972015  0.000000000
  0.603   0.8972015  0.000000000
  0.604   0.8972015  0.000000000
  0.605   0.8972015  0.000000000
  0.606   0.8972015  0.000000000
  0.607   0.8972015  0.000000000
  0.608   0.8972015  0.000000000
  0.609   0.8972015  0.000000000
  0.610   0.8972015  0.000000000
  0.611   0.8972015  0.000000000
  0.612   0.8972015  0.000000000
  0.613   0.8972015  0.000000000
  0.614   0.8972015  0.000000000
  0.615   0.8972015  0.000000000
  0.616   0.8972015  0.000000000
  0.617   0.8972015  0.000000000
  0.618   0.8972015  0.000000000
  0.619   0.8972015  0.000000000
  0.620   0.8972015  0.000000000
  0.621   0.8972015  0.000000000
  0.622   0.8972015  0.000000000
  0.623   0.8972015  0.000000000
  0.624   0.8972015  0.000000000
  0.625   0.8972015  0.000000000
  0.626   0.8972015  0.000000000
  0.627   0.8972015  0.000000000
  0.628   0.8972015  0.000000000
  0.629   0.8972015  0.000000000
  0.630   0.8972015  0.000000000
  0.631   0.8972015  0.000000000
  0.632   0.8972015  0.000000000
  0.633   0.8972015  0.000000000
  0.634   0.8972015  0.000000000
  0.635   0.8972015  0.000000000
  0.636   0.8972015  0.000000000
  0.637   0.8972015  0.000000000
  0.638   0.8972015  0.000000000
  0.639   0.8972015  0.000000000
  0.640   0.8972015  0.000000000
  0.641   0.8972015  0.000000000
  0.642   0.8972015  0.000000000
  0.643   0.8972015  0.000000000
  0.644   0.8972015  0.000000000
  0.645   0.8972015  0.000000000
  0.646   0.8972015  0.000000000
  0.647   0.8972015  0.000000000
  0.648   0.8972015  0.000000000
  0.649   0.8972015  0.000000000
  0.650   0.8972015  0.000000000
  0.651   0.8972015  0.000000000
  0.652   0.8972015  0.000000000
  0.653   0.8972015  0.000000000
  0.654   0.8972015  0.000000000
  0.655   0.8972015  0.000000000
  0.656   0.8972015  0.000000000
  0.657   0.8972015  0.000000000
  0.658   0.8972015  0.000000000
  0.659   0.8972015  0.000000000
  0.660   0.8972015  0.000000000
  0.661   0.8972015  0.000000000
  0.662   0.8972015  0.000000000
  0.663   0.8972015  0.000000000
  0.664   0.8972015  0.000000000
  0.665   0.8972015  0.000000000
  0.666   0.8972015  0.000000000
  0.667   0.8972015  0.000000000
  0.668   0.8972015  0.000000000
  0.669   0.8972015  0.000000000
  0.670   0.8972015  0.000000000
  0.671   0.8972015  0.000000000
  0.672   0.8972015  0.000000000
  0.673   0.8972015  0.000000000
  0.674   0.8972015  0.000000000
  0.675   0.8972015  0.000000000
  0.676   0.8972015  0.000000000
  0.677   0.8972015  0.000000000
  0.678   0.8972015  0.000000000
  0.679   0.8972015  0.000000000
  0.680   0.8972015  0.000000000
  0.681   0.8972015  0.000000000
  0.682   0.8972015  0.000000000
  0.683   0.8972015  0.000000000
  0.684   0.8972015  0.000000000
  0.685   0.8972015  0.000000000
  0.686   0.8972015  0.000000000
  0.687   0.8972015  0.000000000
  0.688   0.8972015  0.000000000
  0.689   0.8972015  0.000000000
  0.690   0.8972015  0.000000000
  0.691   0.8972015  0.000000000
  0.692   0.8972015  0.000000000
  0.693   0.8972015  0.000000000
  0.694   0.8972015  0.000000000
  0.695   0.8972015  0.000000000
  0.696   0.8972015  0.000000000
  0.697   0.8972015  0.000000000
  0.698   0.8972015  0.000000000
  0.699   0.8972015  0.000000000
  0.700   0.8972015  0.000000000
  0.701   0.8972015  0.000000000
  0.702   0.8972015  0.000000000
  0.703   0.8972015  0.000000000
  0.704   0.8972015  0.000000000
  0.705   0.8972015  0.000000000
  0.706   0.8972015  0.000000000
  0.707   0.8972015  0.000000000
  0.708   0.8972015  0.000000000
  0.709   0.8972015  0.000000000
  0.710   0.8972015  0.000000000
  0.711   0.8972015  0.000000000
  0.712   0.8972015  0.000000000
  0.713   0.8972015  0.000000000
  0.714   0.8972015  0.000000000
  0.715   0.8972015  0.000000000
  0.716   0.8972015  0.000000000
  0.717   0.8972015  0.000000000
  0.718   0.8972015  0.000000000
  0.719   0.8972015  0.000000000
  0.720   0.8972015  0.000000000
  0.721   0.8972015  0.000000000
  0.722   0.8972015  0.000000000
  0.723   0.8972015  0.000000000
  0.724   0.8972015  0.000000000
  0.725   0.8972015  0.000000000
  0.726   0.8972015  0.000000000
  0.727   0.8972015  0.000000000
  0.728   0.8972015  0.000000000
  0.729   0.8972015  0.000000000
  0.730   0.8972015  0.000000000
  0.731   0.8972015  0.000000000
  0.732   0.8972015  0.000000000
  0.733   0.8972015  0.000000000
  0.734   0.8972015  0.000000000
  0.735   0.8972015  0.000000000
  0.736   0.8972015  0.000000000
  0.737   0.8972015  0.000000000
  0.738   0.8972015  0.000000000
  0.739   0.8972015  0.000000000
  0.740   0.8972015  0.000000000
  0.741   0.8972015  0.000000000
  0.742   0.8972015  0.000000000
  0.743   0.8972015  0.000000000
  0.744   0.8972015  0.000000000
  0.745   0.8972015  0.000000000
  0.746   0.8972015  0.000000000
  0.747   0.8972015  0.000000000
  0.748   0.8972015  0.000000000
  0.749   0.8972015  0.000000000
  0.750   0.8972015  0.000000000
  0.751   0.8972015  0.000000000
  0.752   0.8972015  0.000000000
  0.753   0.8972015  0.000000000
  0.754   0.8972015  0.000000000
  0.755   0.8972015  0.000000000
  0.756   0.8972015  0.000000000
  0.757   0.8972015  0.000000000
  0.758   0.8972015  0.000000000
  0.759   0.8972015  0.000000000
  0.760   0.8972015  0.000000000
  0.761   0.8972015  0.000000000
  0.762   0.8972015  0.000000000
  0.763   0.8972015  0.000000000
  0.764   0.8972015  0.000000000
  0.765   0.8972015  0.000000000
  0.766   0.8972015  0.000000000
  0.767   0.8972015  0.000000000
  0.768   0.8972015  0.000000000
  0.769   0.8972015  0.000000000
  0.770   0.8972015  0.000000000
  0.771   0.8972015  0.000000000
  0.772   0.8972015  0.000000000
  0.773   0.8972015  0.000000000
  0.774   0.8972015  0.000000000
  0.775   0.8972015  0.000000000
  0.776   0.8972015  0.000000000
  0.777   0.8972015  0.000000000
  0.778   0.8972015  0.000000000
  0.779   0.8972015  0.000000000
  0.780   0.8972015  0.000000000
  0.781   0.8972015  0.000000000
  0.782   0.8972015  0.000000000
  0.783   0.8972015  0.000000000
  0.784   0.8972015  0.000000000
  0.785   0.8972015  0.000000000
  0.786   0.8972015  0.000000000
  0.787   0.8972015  0.000000000
  0.788   0.8972015  0.000000000
  0.789   0.8972015  0.000000000
  0.790   0.8972015  0.000000000
  0.791   0.8972015  0.000000000
  0.792   0.8972015  0.000000000
  0.793   0.8972015  0.000000000
  0.794   0.8972015  0.000000000
  0.795   0.8972015  0.000000000
  0.796   0.8972015  0.000000000
  0.797   0.8972015  0.000000000
  0.798   0.8972015  0.000000000
  0.799   0.8972015  0.000000000
  0.800   0.8972015  0.000000000
  0.801   0.8972015  0.000000000
  0.802   0.8972015  0.000000000
  0.803   0.8972015  0.000000000
  0.804   0.8972015  0.000000000
  0.805   0.8972015  0.000000000
  0.806   0.8972015  0.000000000
  0.807   0.8972015  0.000000000
  0.808   0.8972015  0.000000000
  0.809   0.8972015  0.000000000
  0.810   0.8972015  0.000000000
  0.811   0.8972015  0.000000000
  0.812   0.8972015  0.000000000
  0.813   0.8972015  0.000000000
  0.814   0.8972015  0.000000000
  0.815   0.8972015  0.000000000
  0.816   0.8972015  0.000000000
  0.817   0.8972015  0.000000000
  0.818   0.8972015  0.000000000
  0.819   0.8972015  0.000000000
  0.820   0.8972015  0.000000000
  0.821   0.8972015  0.000000000
  0.822   0.8972015  0.000000000
  0.823   0.8972015  0.000000000
  0.824   0.8972015  0.000000000
  0.825   0.8972015  0.000000000
  0.826   0.8972015  0.000000000
  0.827   0.8972015  0.000000000
  0.828   0.8972015  0.000000000
  0.829   0.8972015  0.000000000
  0.830   0.8972015  0.000000000
  0.831   0.8972015  0.000000000
  0.832   0.8972015  0.000000000
  0.833   0.8972015  0.000000000
  0.834   0.8972015  0.000000000
  0.835   0.8972015  0.000000000
  0.836   0.8972015  0.000000000
  0.837   0.8972015  0.000000000
  0.838   0.8972015  0.000000000
  0.839   0.8972015  0.000000000
  0.840   0.8972015  0.000000000
  0.841   0.8972015  0.000000000
  0.842   0.8972015  0.000000000
  0.843   0.8972015  0.000000000
  0.844   0.8972015  0.000000000
  0.845   0.8972015  0.000000000
  0.846   0.8972015  0.000000000
  0.847   0.8972015  0.000000000
  0.848   0.8972015  0.000000000
  0.849   0.8972015  0.000000000
  0.850   0.8972015  0.000000000
  0.851   0.8972015  0.000000000
  0.852   0.8972015  0.000000000
  0.853   0.8972015  0.000000000
  0.854   0.8972015  0.000000000
  0.855   0.8972015  0.000000000
  0.856   0.8972015  0.000000000
  0.857   0.8972015  0.000000000
  0.858   0.8972015  0.000000000
  0.859   0.8972015  0.000000000
  0.860   0.8972015  0.000000000
  0.861   0.8972015  0.000000000
  0.862   0.8972015  0.000000000
  0.863   0.8972015  0.000000000
  0.864   0.8972015  0.000000000
  0.865   0.8972015  0.000000000
  0.866   0.8972015  0.000000000
  0.867   0.8972015  0.000000000
  0.868   0.8972015  0.000000000
  0.869   0.8972015  0.000000000
  0.870   0.8972015  0.000000000
  0.871   0.8972015  0.000000000
  0.872   0.8972015  0.000000000
  0.873   0.8972015  0.000000000
  0.874   0.8972015  0.000000000
  0.875   0.8972015  0.000000000
  0.876   0.8972015  0.000000000
  0.877   0.8972015  0.000000000
  0.878   0.8972015  0.000000000
  0.879   0.8972015  0.000000000
  0.880   0.8972015  0.000000000
  0.881   0.8972015  0.000000000
  0.882   0.8972015  0.000000000
  0.883   0.8972015  0.000000000
  0.884   0.8972015  0.000000000
  0.885   0.8972015  0.000000000
  0.886   0.8972015  0.000000000
  0.887   0.8972015  0.000000000
  0.888   0.8972015  0.000000000
  0.889   0.8972015  0.000000000
  0.890   0.8972015  0.000000000
  0.891   0.8972015  0.000000000
  0.892   0.8972015  0.000000000
  0.893   0.8972015  0.000000000
  0.894   0.8972015  0.000000000
  0.895   0.8972015  0.000000000
  0.896   0.8972015  0.000000000
  0.897   0.8972015  0.000000000
  0.898   0.8972015  0.000000000
  0.899   0.8972015  0.000000000
  0.900   0.8972015  0.000000000
  0.901   0.8972015  0.000000000
  0.902   0.8972015  0.000000000
  0.903   0.8972015  0.000000000
  0.904   0.8972015  0.000000000
  0.905   0.8972015  0.000000000
  0.906   0.8972015  0.000000000
  0.907   0.8972015  0.000000000
  0.908   0.8972015  0.000000000
  0.909   0.8972015  0.000000000
  0.910   0.8972015  0.000000000
  0.911   0.8972015  0.000000000
  0.912   0.8972015  0.000000000
  0.913   0.8972015  0.000000000
  0.914   0.8972015  0.000000000
  0.915   0.8972015  0.000000000
  0.916   0.8972015  0.000000000
  0.917   0.8972015  0.000000000
  0.918   0.8972015  0.000000000
  0.919   0.8972015  0.000000000
  0.920   0.8972015  0.000000000
  0.921   0.8972015  0.000000000
  0.922   0.8972015  0.000000000
  0.923   0.8972015  0.000000000
  0.924   0.8972015  0.000000000
  0.925   0.8972015  0.000000000
  0.926   0.8972015  0.000000000
  0.927   0.8972015  0.000000000
  0.928   0.8972015  0.000000000
  0.929   0.8972015  0.000000000
  0.930   0.8972015  0.000000000
  0.931   0.8972015  0.000000000
  0.932   0.8972015  0.000000000
  0.933   0.8972015  0.000000000
  0.934   0.8972015  0.000000000
  0.935   0.8972015  0.000000000
  0.936   0.8972015  0.000000000
  0.937   0.8972015  0.000000000
  0.938   0.8972015  0.000000000
  0.939   0.8972015  0.000000000
  0.940   0.8972015  0.000000000
  0.941   0.8972015  0.000000000
  0.942   0.8972015  0.000000000
  0.943   0.8972015  0.000000000
  0.944   0.8972015  0.000000000
  0.945   0.8972015  0.000000000
  0.946   0.8972015  0.000000000
  0.947   0.8972015  0.000000000
  0.948   0.8972015  0.000000000
  0.949   0.8972015  0.000000000
  0.950   0.8972015  0.000000000
  0.951   0.8972015  0.000000000
  0.952   0.8972015  0.000000000
  0.953   0.8972015  0.000000000
  0.954   0.8972015  0.000000000
  0.955   0.8972015  0.000000000
  0.956   0.8972015  0.000000000
  0.957   0.8972015  0.000000000
  0.958   0.8972015  0.000000000
  0.959   0.8972015  0.000000000
  0.960   0.8972015  0.000000000
  0.961   0.8972015  0.000000000
  0.962   0.8972015  0.000000000
  0.963   0.8972015  0.000000000
  0.964   0.8972015  0.000000000
  0.965   0.8972015  0.000000000
  0.966   0.8972015  0.000000000
  0.967   0.8972015  0.000000000
  0.968   0.8972015  0.000000000
  0.969   0.8972015  0.000000000
  0.970   0.8972015  0.000000000
  0.971   0.8972015  0.000000000
  0.972   0.8972015  0.000000000
  0.973   0.8972015  0.000000000
  0.974   0.8972015  0.000000000
  0.975   0.8972015  0.000000000
  0.976   0.8972015  0.000000000
  0.977   0.8972015  0.000000000
  0.978   0.8972015  0.000000000
  0.979   0.8972015  0.000000000
  0.980   0.8972015  0.000000000
  0.981   0.8972015  0.000000000
  0.982   0.8972015  0.000000000
  0.983   0.8972015  0.000000000
  0.984   0.8972015  0.000000000
  0.985   0.8972015  0.000000000
  0.986   0.8972015  0.000000000
  0.987   0.8972015  0.000000000
  0.988   0.8972015  0.000000000
  0.989   0.8972015  0.000000000
  0.990   0.8972015  0.000000000
  0.991   0.8972015  0.000000000
  0.992   0.8972015  0.000000000
  0.993   0.8972015  0.000000000
  0.994   0.8972015  0.000000000
  0.995   0.8972015  0.000000000
  0.996   0.8972015  0.000000000
  0.997   0.8972015  0.000000000
  0.998   0.8972015  0.000000000
  0.999   0.8972015  0.000000000
  1.000   0.8972015  0.000000000

Tuning parameter 'alpha' was held constant at a value of 1
Accuracy was used to select the optimal model using the
 largest value.
The final values used for the model were alpha = 1 and lambda = 0.001.
plot(lasso.fit)                                                       # Plot
lasso.fit$bestTune                                                    # lambda의 최적값
  alpha lambda
2     1  0.001

Result! lambda = 0.001일 때 정확도가 가장 높은 것을 알 수 있으며, lambda = 0.001를 가지는 모형을 최적의 훈련된 모형으로 선택한다.

round(coef(lasso.fit$finalModel, lasso.fit$bestTune$lambda), 3)       # lambda의 최적값에 대한 회귀계수 추정치
16 x 1 sparse Matrix of class "dgCMatrix"
                        s1
(Intercept)         -4.550
Age                  0.092
Experience           .    
Income               2.449
ZIP.Code             0.054
Family2             -0.129
Family3              0.716
Family4              0.666
CCAvg                0.354
Education2           1.373
Education3           1.420
Mortgage             0.042
Securities.Account1 -0.347
CD.Account1          0.963
Online1             -0.132
CreditCard1         -0.504

Result! 데이터 “UB.trd”의 Target “Personal.Loan”은 “no”와 “yes” 2개의 클래스를 가지며, “Factor” 변환하면 알파벳순으로 수준을 부여하기 때문에 “yes”가 두 번째 클래스가 된다. 즉, “yes”에 속할 확률(= 개인 대출 제의를 수락할 확률)을 \(p\)라고 할 때, 추정된 회귀계수를 이용하여 다음과 같은 모형식을 얻을 수 있다. \[ \begin{align*} \log{\frac{p}{1-p}} = &-4.550 +0.092 Z_{\text{Age}} + 2.449 Z_{\text{Income}} \\ &+0.054 Z_{\text{ZIP.Code}} -0.129 Z_{\text{Family2}} + 0.716 Z_{\text{Family3}} + 0.666 Z_{\text{Family4}} \\ &+ 0.354 Z_{\text{CCAvg}} + 1.373 Z_{\text{Education2}} + 1.420 Z_{\text{Education3}} + 0.042 Z_{\text{Mortgage}} \\ &-0.347 Z_{\text{Securities.Account1}} + 0.963 Z_{\text{CD.Account1}} -0.132 Z_{\text{Online1}} -0.504 Z_{\text{CreditCard1}} \end{align*} \] 여기서, \(Z_{\text{예측 변수}}\)는 표준화한 예측 변수를 의미한다.
범주형 예측 변수(“Family”, “Education”, “Securities.Account”, “CD.Account”, “Online”, “CreditCard”)는 더미 변환이 수행되었는데, 예를 들어, Family2는 가족 수가 2명인 경우 “1”값을 가지고 2명이 아니면 “0”값을 가진다.


6. 모형 평가

Caution! 모형 평가를 위해 Test Dataset에 대한 예측 class/확률 이 필요하며, 함수 predict()를 이용하여 생성한다.
# 예측 class 생성
test.lasso.class <- predict(lasso.fit, 
                            newdata = UB.ted[,-9])      # Test Dataset including Only 예측 변수  

test.lasso.class %>%                                      
  as_tibble
# A tibble: 749 × 1
   value
   <fct>
 1 no   
 2 no   
 3 no   
 4 no   
 5 no   
 6 no   
 7 no   
 8 no   
 9 no   
10 no   
# ℹ 739 more rows


6-1. ConfusionMatrix

CM   <- caret::confusionMatrix(test.lasso.class, UB.ted$Personal.Loan, 
                               positive = "yes")        # confusionMatrix(예측 class, 실제 class, positive = "관심 class")
CM
Confusion Matrix and Statistics

          Reference
Prediction  no yes
       no  667  24
       yes   6  52
                                          
               Accuracy : 0.9599          
                 95% CI : (0.9433, 0.9728)
    No Information Rate : 0.8985          
    P-Value [Acc > NIR] : 3.394e-10       
                                          
                  Kappa : 0.7546          
                                          
 Mcnemar's Test P-Value : 0.001911        
                                          
            Sensitivity : 0.68421         
            Specificity : 0.99108         
         Pos Pred Value : 0.89655         
         Neg Pred Value : 0.96527         
             Prevalence : 0.10147         
         Detection Rate : 0.06943         
   Detection Prevalence : 0.07744         
      Balanced Accuracy : 0.83765         
                                          
       'Positive' Class : yes             
                                          


6-2. ROC 곡선

# 예측 확률 생성
test.lasso.prob <- predict(lasso.fit, 
                           newdata = UB.ted[,-9],      # Test Dataset including Only 예측 변수 
                           type = "prob")              # 예측 확률 생성


test.lasso.prob %>%                                                         
  as_tibble
# A tibble: 749 × 2
      no      yes
   <dbl>    <dbl>
 1 1.00  0.000393
 2 0.994 0.00633 
 3 0.999 0.000519
 4 1.00  0.000159
 5 0.993 0.00684 
 6 0.998 0.00225 
 7 0.975 0.0250  
 8 0.892 0.108   
 9 0.907 0.0927  
10 0.980 0.0203  
# ℹ 739 more rows
test.lasso.prob <- test.lasso.prob[,2]                 # "Personal.Loan = yes"에 대한 예측 확률

ac  <- UB.ted$Personal.Loan                            # Test Dataset의 실제 class 
pp  <- as.numeric(test.lasso.prob)                     # 예측 확률을 수치형으로 변환

1) Package “pROC”

pacman::p_load("pROC")

lasso.roc  <- roc(ac, pp, plot = T, col = "gray")      # roc(실제 class, 예측 확률)
auc        <- round(auc(lasso.roc), 3)
legend("bottomright", legend = auc, bty = "n")

Caution! Package "pROC"를 통해 출력한 ROC 곡선은 다양한 함수를 이용해서 그래프를 수정할 수 있다.

# 함수 plot.roc() 이용
plot.roc(lasso.roc,   
         col="gray",                                   # Line Color
         print.auc = TRUE,                             # AUC 출력 여부
         print.auc.col = "red",                        # AUC 글씨 색깔
         print.thres = TRUE,                           # Cutoff Value 출력 여부
         print.thres.pch = 19,                         # Cutoff Value를 표시하는 도형 모양
         print.thres.col = "red",                      # Cutoff Value를 표시하는 도형의 색깔
         auc.polygon = TRUE,                           # 곡선 아래 면적에 대한 여부
         auc.polygon.col = "gray90")                   # 곡선 아래 면적의 색깔

# 함수 ggroc() 이용
ggroc(lasso.roc) +
annotate(geom = "text", x = 0.9, y = 1.0,
label = paste("AUC = ", auc),
size = 5,
color="red") +
theme_bw()

2) Package “Epi”

pacman::p_load("Epi")       
# install_version("etm", version = "1.1", repos = "http://cran.us.r-project.org")

ROC(pp, ac, plot = "ROC")                              # ROC(예측 확률, 실제 class)  

3) Package “ROCR”

pacman::p_load("ROCR")

lasso.pred <- prediction(pp, ac)                       # prediction(예측 확률, 실제 class) 

lasso.perf <- performance(lasso.pred, "tpr", "fpr")    # performance(, "민감도", "1-특이도")                      
plot(lasso.perf, col = "gray")                         # ROC Curve

perf.auc   <- performance(lasso.pred, "auc")           # AUC
auc        <- attributes(perf.auc)$y.values
legend("bottomright", legend = auc, bty = "n")


6-3. 향상 차트

1) Package “ROCR”

lasso.perf <- performance(lasso.pred, "lift", "rpp")   # Lift Chart                      
plot(lasso.perf, main = "lift curve",
     colorize = T,                                     # Coloring according to cutoff 
     lwd = 2) 

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".