Install necessary packages

library(arules)
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
library(arulesViz)
library(ggplot2)

Set working directory

setwd("/Users/emma/Documents/SYRACUSE/IST707/Week3")

Prep Data

bank <- read.csv("/Users/emma/Documents/SYRACUSE/IST707/Week3/bankdata_csv_all.csv", header = TRUE, blank.lines.skip = TRUE, stringsAsFactors = TRUE)
summary(bank)
##        id           age            sex             region        income     
##  ID12101:  1   Min.   :18.00   FEMALE:300   INNER_CITY:269   Min.   : 5014  
##  ID12102:  1   1st Qu.:30.00   MALE  :300   RURAL     : 96   1st Qu.:17264  
##  ID12103:  1   Median :42.00                SUBURBAN  : 62   Median :24925  
##  ID12104:  1   Mean   :42.40                TOWN      :173   Mean   :27524  
##  ID12105:  1   3rd Qu.:55.25                                 3rd Qu.:36173  
##  ID12106:  1   Max.   :67.00                                 Max.   :63130  
##  (Other):594                                                                
##  married      children      car      save_act  current_act mortgage   pep     
##  NO :204   Min.   :0.000   NO :304   NO :186   NO :145     NO :391   NO :326  
##  YES:396   1st Qu.:0.000   YES:296   YES:414   YES:455     YES:209   YES:274  
##            Median :1.000                                                      
##            Mean   :1.012                                                      
##            3rd Qu.:2.000                                                      
##            Max.   :3.000                                                      
## 
str(bank)
## 'data.frame':    600 obs. of  12 variables:
##  $ id         : Factor w/ 600 levels "ID12101","ID12102",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ age        : int  48 40 51 23 57 57 22 58 37 54 ...
##  $ sex        : Factor w/ 2 levels "FEMALE","MALE": 1 2 1 1 1 1 2 2 1 2 ...
##  $ region     : Factor w/ 4 levels "INNER_CITY","RURAL",..: 1 4 1 4 2 4 2 4 3 4 ...
##  $ income     : num  17546 30085 16575 20375 50576 ...
##  $ married    : Factor w/ 2 levels "NO","YES": 1 2 2 2 2 2 1 2 2 2 ...
##  $ children   : int  1 3 0 3 0 2 0 0 2 2 ...
##  $ car        : Factor w/ 2 levels "NO","YES": 1 2 2 1 1 1 1 2 2 2 ...
##  $ save_act   : Factor w/ 2 levels "NO","YES": 1 1 2 1 2 2 1 2 1 2 ...
##  $ current_act: Factor w/ 2 levels "NO","YES": 1 2 2 2 1 2 2 2 1 2 ...
##  $ mortgage   : Factor w/ 2 levels "NO","YES": 1 2 1 1 1 1 1 1 1 1 ...
##  $ pep        : Factor w/ 2 levels "NO","YES": 2 1 1 1 1 2 2 1 1 1 ...

Remove ID column

bank <- bank[,-1]
str(bank)
## 'data.frame':    600 obs. of  11 variables:
##  $ age        : int  48 40 51 23 57 57 22 58 37 54 ...
##  $ sex        : Factor w/ 2 levels "FEMALE","MALE": 1 2 1 1 1 1 2 2 1 2 ...
##  $ region     : Factor w/ 4 levels "INNER_CITY","RURAL",..: 1 4 1 4 2 4 2 4 3 4 ...
##  $ income     : num  17546 30085 16575 20375 50576 ...
##  $ married    : Factor w/ 2 levels "NO","YES": 1 2 2 2 2 2 1 2 2 2 ...
##  $ children   : int  1 3 0 3 0 2 0 0 2 2 ...
##  $ car        : Factor w/ 2 levels "NO","YES": 1 2 2 1 1 1 1 2 2 2 ...
##  $ save_act   : Factor w/ 2 levels "NO","YES": 1 1 2 1 2 2 1 2 1 2 ...
##  $ current_act: Factor w/ 2 levels "NO","YES": 1 2 2 2 1 2 2 2 1 2 ...
##  $ mortgage   : Factor w/ 2 levels "NO","YES": 1 2 1 1 1 1 1 1 1 1 ...
##  $ pep        : Factor w/ 2 levels "NO","YES": 2 1 1 1 1 2 2 1 1 1 ...

Discretize age, income, and # children as factor

bank$age <- discretize(bank$age, method="frequency", breaks= 3, labels = c('young', 'middle-age', 'old'), order=TRUE)


bank$income <- discretize(bank$income, method="frequency", breaks = 5, labels = c('lowest-income', 'low-income', 'average-income',
                                                                                  'high-income', 'highest-income'), order=TRUE )

bank$children <- as.factor(bank$children)
str(bank)
## 'data.frame':    600 obs. of  11 variables:
##  $ age        : Ord.factor w/ 3 levels "young"<"middle-age"<..: 2 2 3 1 3 3 1 3 2 3 ...
##   ..- attr(*, "discretized:breaks")= num [1:4] 18 35 49 67
##   ..- attr(*, "discretized:method")= chr "frequency"
##  $ sex        : Factor w/ 2 levels "FEMALE","MALE": 1 2 1 1 1 1 2 2 1 2 ...
##  $ region     : Factor w/ 4 levels "INNER_CITY","RURAL",..: 1 4 1 4 2 4 2 4 3 4 ...
##  $ income     : Ord.factor w/ 5 levels "lowest-income"<..: 2 4 2 2 5 4 1 3 3 3 ...
##   ..- attr(*, "discretized:breaks")= num [1:6] 5014 15838 22162 28480 38448 ...
##   ..- attr(*, "discretized:method")= chr "frequency"
##  $ married    : Factor w/ 2 levels "NO","YES": 1 2 2 2 2 2 1 2 2 2 ...
##  $ children   : Factor w/ 4 levels "0","1","2","3": 2 4 1 4 1 3 1 1 3 3 ...
##  $ car        : Factor w/ 2 levels "NO","YES": 1 2 2 1 1 1 1 2 2 2 ...
##  $ save_act   : Factor w/ 2 levels "NO","YES": 1 1 2 1 2 2 1 2 1 2 ...
##  $ current_act: Factor w/ 2 levels "NO","YES": 1 2 2 2 1 2 2 2 1 2 ...
##  $ mortgage   : Factor w/ 2 levels "NO","YES": 1 2 1 1 1 1 1 1 1 1 ...
##  $ pep        : Factor w/ 2 levels "NO","YES": 2 1 1 1 1 2 2 1 1 1 ...

Association rule discovery, 20-30 strong rules with high lift and confidence

Rule that is likely to result in a RHS “FEMALE”

FEMALE_rules <- apriori(bank, parameter=list(supp=.1, conf=.5), 
                       appearance=list(default="lhs", rhs="sex=FEMALE"),
                       control=list(verbose=F))
FEMALE_rules
## set of 104 rules
FEMALE_rules <- sort(FEMALE_rules, by="lift", decreasing=TRUE)
inspect(FEMALE_rules[1:20])
##      lhs                    rhs            support confidence  coverage     lift count
## [1]  {married=YES,                                                                    
##       children=0,                                                                     
##       mortgage=NO,                                                                    
##       pep=NO}            => {sex=FEMALE} 0.1050000  0.6057692 0.1733333 1.211538    63
## [2]  {married=YES,                                                                    
##       children=0,                                                                     
##       mortgage=NO}       => {sex=FEMALE} 0.1166667  0.6034483 0.1933333 1.206897    70
## [3]  {children=0,                                                                     
##       mortgage=NO,                                                                    
##       pep=NO}            => {sex=FEMALE} 0.1066667  0.5981308 0.1783333 1.196262    64
## [4]  {car=NO,                                                                         
##       mortgage=NO,                                                                    
##       pep=NO}            => {sex=FEMALE} 0.1066667  0.5925926 0.1800000 1.185185    64
## [5]  {age=old,                                                                        
##       current_act=YES,                                                                
##       mortgage=NO}       => {sex=FEMALE} 0.1083333  0.5909091 0.1833333 1.181818    65
## [6]  {children=0,                                                                     
##       current_act=YES,                                                                
##       mortgage=NO}       => {sex=FEMALE} 0.1216667  0.5840000 0.2083333 1.168000    73
## [7]  {region=TOWN,                                                                    
##       married=YES}       => {sex=FEMALE} 0.1116667  0.5826087 0.1916667 1.165217    67
## [8]  {car=NO,                                                                         
##       save_act=YES,                                                                   
##       mortgage=NO}       => {sex=FEMALE} 0.1250000  0.5813953 0.2150000 1.162791    75
## [9]  {married=YES,                                                                    
##       car=NO,                                                                         
##       current_act=YES,                                                                
##       mortgage=NO}       => {sex=FEMALE} 0.1000000  0.5769231 0.1733333 1.153846    60
## [10] {age=old,                                                                        
##       current_act=YES}   => {sex=FEMALE} 0.1516667  0.5759494 0.2633333 1.151899    91
## [11] {age=old,                                                                        
##       mortgage=NO}       => {sex=FEMALE} 0.1333333  0.5755396 0.2316667 1.151079    80
## [12] {married=YES,                                                                    
##       car=NO,                                                                         
##       mortgage=NO}       => {sex=FEMALE} 0.1266667  0.5714286 0.2216667 1.142857    76
## [13] {married=YES,                                                                    
##       children=0,                                                                     
##       current_act=YES,                                                                
##       pep=NO}            => {sex=FEMALE} 0.1000000  0.5714286 0.1750000 1.142857    60
## [14] {age=old}           => {sex=FEMALE} 0.1983333  0.5666667 0.3500000 1.133333   119
## [15] {age=old,                                                                        
##       car=YES}           => {sex=FEMALE} 0.1066667  0.5663717 0.1883333 1.132743    64
## [16] {car=NO,                                                                         
##       mortgage=NO}       => {sex=FEMALE} 0.1833333  0.5583756 0.3283333 1.116751   110
## [17] {region=INNER_CITY,                                                              
##       current_act=YES,                                                                
##       pep=NO}            => {sex=FEMALE} 0.1066667  0.5565217 0.1916667 1.113043    64
## [18] {region=TOWN,                                                                    
##       mortgage=NO}       => {sex=FEMALE} 0.1000000  0.5555556 0.1800000 1.111111    60
## [19] {children=0,                                                                     
##       mortgage=NO}       => {sex=FEMALE} 0.1516667  0.5548780 0.2733333 1.109756    91
## [20] {save_act=NO,                                                                    
##       mortgage=NO}       => {sex=FEMALE} 0.1116667  0.5537190 0.2016667 1.107438    67
inspectDT(FEMALE_rules[1:20])

Rule that is likely to result in a RHS “MALE”

MALE_rules <- apriori(bank, parameter=list(supp=.1, conf=.5), 
                        appearance=list(default="lhs", rhs="sex=MALE"),
                        control=list(verbose=F))
MALE_rules
## set of 59 rules
MALE_rules <- sort(MALE_rules, by="lift", decreasing=TRUE)
inspect(MALE_rules[1:20])
##      lhs                                      rhs        support   confidence
## [1]  {car=NO,mortgage=YES}                 => {sex=MALE} 0.1066667 0.5981308 
## [2]  {married=YES,mortgage=YES}            => {sex=MALE} 0.1300000 0.5777778 
## [3]  {region=INNER_CITY,pep=YES}           => {sex=MALE} 0.1150000 0.5609756 
## [4]  {married=YES,pep=YES}                 => {sex=MALE} 0.1433333 0.5584416 
## [5]  {age=middle-age,current_act=YES}      => {sex=MALE} 0.1333333 0.5555556 
## [6]  {car=YES,save_act=YES,mortgage=NO}    => {sex=MALE} 0.1300000 0.5531915 
## [7]  {age=middle-age}                      => {sex=MALE} 0.1783333 0.5487179 
## [8]  {region=INNER_CITY,car=NO}            => {sex=MALE} 0.1266667 0.5467626 
## [9]  {mortgage=YES}                        => {sex=MALE} 0.1900000 0.5454545 
## [10] {car=YES,pep=YES}                     => {sex=MALE} 0.1250000 0.5434783 
## [11] {married=YES,current_act=YES,pep=YES} => {sex=MALE} 0.1050000 0.5431034 
## [12] {current_act=YES,mortgage=YES}        => {sex=MALE} 0.1383333 0.5389610 
## [13] {age=middle-age,save_act=YES}         => {sex=MALE} 0.1166667 0.5384615 
## [14] {age=middle-age,married=YES}          => {sex=MALE} 0.1166667 0.5343511 
## [15] {save_act=YES,pep=YES}                => {sex=MALE} 0.1583333 0.5307263 
## [16] {mortgage=YES,pep=NO}                 => {sex=MALE} 0.1033333 0.5299145 
## [17] {region=INNER_CITY,married=YES}       => {sex=MALE} 0.1566667 0.5280899 
## [18] {save_act=YES,mortgage=YES}           => {sex=MALE} 0.1266667 0.5277778 
## [19] {pep=YES}                             => {sex=MALE} 0.2400000 0.5255474 
## [20] {income=lowest-income}                => {sex=MALE} 0.1050000 0.5250000 
##      coverage  lift     count
## [1]  0.1783333 1.196262  64  
## [2]  0.2250000 1.155556  78  
## [3]  0.2050000 1.121951  69  
## [4]  0.2566667 1.116883  86  
## [5]  0.2400000 1.111111  80  
## [6]  0.2350000 1.106383  78  
## [7]  0.3250000 1.097436 107  
## [8]  0.2316667 1.093525  76  
## [9]  0.3483333 1.090909 114  
## [10] 0.2300000 1.086957  75  
## [11] 0.1933333 1.086207  63  
## [12] 0.2566667 1.077922  83  
## [13] 0.2166667 1.076923  70  
## [14] 0.2183333 1.068702  70  
## [15] 0.2983333 1.061453  95  
## [16] 0.1950000 1.059829  62  
## [17] 0.2966667 1.056180  94  
## [18] 0.2400000 1.055556  76  
## [19] 0.4566667 1.051095 144  
## [20] 0.2000000 1.050000  63
inspectDT(MALE_rules[1:20])

Income prediction rules

Rule that is likely to result in a RHS “income=lowest-income”

Lowest_Income_rules <- apriori(bank, parameter=list(supp=.05, conf=.25), 
                          appearance=list(default="lhs", rhs="income=lowest-income"),
                          control=list(verbose=F))
Lowest_Income_rules
## set of 112 rules
Lowest_Income_rules<- sort(Lowest_Income_rules, by="lift", decreasing=TRUE)
inspect(Lowest_Income_rules[1:15])
##      lhs                    rhs                       support confidence   coverage     lift count
## [1]  {age=young,                                                                                  
##       region=INNER_CITY,                                                                          
##       married=YES,                                                                                
##       pep=NO}            => {income=lowest-income} 0.05333333  0.7619048 0.07000000 3.809524    32
## [2]  {age=young,                                                                                  
##       region=INNER_CITY,                                                                          
##       current_act=YES,                                                                            
##       pep=NO}            => {income=lowest-income} 0.05833333  0.7291667 0.08000000 3.645833    35
## [3]  {age=young,                                                                                  
##       region=INNER_CITY,                                                                          
##       pep=NO}            => {income=lowest-income} 0.07000000  0.7118644 0.09833333 3.559322    42
## [4]  {age=young,                                                                                  
##       car=YES,                                                                                    
##       current_act=YES,                                                                            
##       pep=NO}            => {income=lowest-income} 0.05166667  0.6888889 0.07500000 3.444444    31
## [5]  {age=young,                                                                                  
##       save_act=YES,                                                                               
##       current_act=YES,                                                                            
##       pep=NO}            => {income=lowest-income} 0.07166667  0.6718750 0.10666667 3.359375    43
## [6]  {age=young,                                                                                  
##       region=INNER_CITY,                                                                          
##       current_act=YES,                                                                            
##       mortgage=NO}       => {income=lowest-income} 0.05000000  0.6666667 0.07500000 3.333333    30
## [7]  {age=young,                                                                                  
##       sex=FEMALE,                                                                                 
##       current_act=YES,                                                                            
##       pep=NO}            => {income=lowest-income} 0.05500000  0.6600000 0.08333333 3.300000    33
## [8]  {age=young,                                                                                  
##       current_act=YES,                                                                            
##       pep=NO}            => {income=lowest-income} 0.10333333  0.6526316 0.15833333 3.263158    62
## [9]  {age=young,                                                                                  
##       region=INNER_CITY,                                                                          
##       save_act=YES,                                                                               
##       current_act=YES}   => {income=lowest-income} 0.05000000  0.6521739 0.07666667 3.260870    30
## [10] {age=young,                                                                                  
##       married=YES,                                                                                
##       car=NO,                                                                                     
##       pep=NO}            => {income=lowest-income} 0.05000000  0.6521739 0.07666667 3.260870    30
## [11] {age=young,                                                                                  
##       sex=MALE,                                                                                   
##       pep=NO}            => {income=lowest-income} 0.06500000  0.6393443 0.10166667 3.196721    39
## [12] {age=young,                                                                                  
##       car=NO,                                                                                     
##       pep=NO}            => {income=lowest-income} 0.07000000  0.6363636 0.11000000 3.181818    42
## [13] {age=young,                                                                                  
##       married=YES,                                                                                
##       current_act=YES,                                                                            
##       pep=NO}            => {income=lowest-income} 0.07000000  0.6363636 0.11000000 3.181818    42
## [14] {age=young,                                                                                  
##       save_act=YES,                                                                               
##       pep=NO}            => {income=lowest-income} 0.08666667  0.6341463 0.13666667 3.170732    52
## [15] {age=young,                                                                                  
##       married=YES,                                                                                
##       current_act=YES,                                                                            
##       mortgage=NO,                                                                                
##       pep=NO}            => {income=lowest-income} 0.05166667  0.6326531 0.08166667 3.163265    31
inspectDT(Lowest_Income_rules[1:15])

Rule that is likely to result in a RHS “income=low-income”

Low_Income_rules <- apriori(bank, parameter=list(supp=.05, conf=.25), 
                               appearance=list(default="lhs", rhs="income=low-income"),
                               control=list(verbose=F))
Low_Income_rules
## set of 15 rules
Low_Income_rules<- sort(Low_Income_rules, by="lift", decreasing=TRUE)
inspect(Low_Income_rules[1:15])
##      lhs                  rhs                    support confidence  coverage     lift count
## [1]  {age=young,                                                                            
##       married=YES}     => {income=low-income} 0.06666667  0.3125000 0.2133333 1.562500    40
## [2]  {age=young,                                                                            
##       mortgage=NO}     => {income=low-income} 0.06166667  0.2960000 0.2083333 1.480000    37
## [3]  {married=YES,                                                                          
##       car=NO,                                                                               
##       current_act=YES,                                                                      
##       mortgage=NO}     => {income=low-income} 0.05000000  0.2884615 0.1733333 1.442308    30
## [4]  {region=TOWN,                                                                          
##       mortgage=NO}     => {income=low-income} 0.05166667  0.2870370 0.1800000 1.435185    31
## [5]  {age=young}       => {income=low-income} 0.09166667  0.2820513 0.3250000 1.410256    55
## [6]  {age=young,                                                                            
##       car=NO}          => {income=low-income} 0.05000000  0.2803738 0.1783333 1.401869    30
## [7]  {married=YES,                                                                          
##       car=NO,                                                                               
##       mortgage=NO}     => {income=low-income} 0.06000000  0.2706767 0.2216667 1.353383    36
## [8]  {age=young,                                                                            
##       current_act=YES} => {income=low-income} 0.06833333  0.2679739 0.2550000 1.339869    41
## [9]  {age=middle-age,                                                                       
##       married=YES}     => {income=low-income} 0.05833333  0.2671756 0.2183333 1.335878    35
## [10] {married=YES,                                                                          
##       car=NO,                                                                               
##       current_act=YES} => {income=low-income} 0.06666667  0.2649007 0.2516667 1.324503    40
## [11] {married=YES,                                                                          
##       save_act=NO}     => {income=low-income} 0.05166667  0.2605042 0.1983333 1.302521    31
## [12] {age=young,                                                                            
##       save_act=YES}    => {income=low-income} 0.05166667  0.2605042 0.1983333 1.302521    31
## [13] {married=YES,                                                                          
##       car=NO}          => {income=low-income} 0.08500000  0.2524752 0.3366667 1.262376    51
## [14] {age=middle-age,                                                                       
##       mortgage=NO}     => {income=low-income} 0.05333333  0.2519685 0.2116667 1.259843    32
## [15] {save_act=NO,                                                                          
##       current_act=YES} => {income=low-income} 0.05666667  0.2500000 0.2266667 1.250000    34
inspectDT(Low_Income_rules[1:15])

Rule that is likely to result in a RHS “income=average-income”

avg_Income_rules <- apriori(bank, parameter=list(supp=.05, conf=.25), 
                            appearance=list(default="lhs", rhs="income=average-income"),
                            control=list(verbose=F))
avg_Income_rules
## set of 15 rules
avg_Income_rules<- sort(avg_Income_rules, by="lift", decreasing=TRUE)
inspect(avg_Income_rules[1:15])
##      lhs                  rhs                        support confidence  coverage     lift count
## [1]  {children=0,                                                                               
##       save_act=NO}     => {income=average-income} 0.05000000  0.3370787 0.1483333 1.685393    30
## [2]  {car=NO,                                                                                   
##       save_act=NO}     => {income=average-income} 0.05166667  0.3131313 0.1650000 1.565657    31
## [3]  {age=middle-age,                                                                           
##       children=0}      => {income=average-income} 0.05000000  0.3061224 0.1633333 1.530612    30
## [4]  {age=middle-age,                                                                           
##       pep=NO}          => {income=average-income} 0.05500000  0.3055556 0.1800000 1.527778    33
## [5]  {age=middle-age,                                                                           
##       sex=MALE}        => {income=average-income} 0.05166667  0.2897196 0.1783333 1.448598    31
## [6]  {married=YES,                                                                              
##       save_act=NO}     => {income=average-income} 0.05666667  0.2857143 0.1983333 1.428571    34
## [7]  {save_act=NO}     => {income=average-income} 0.08833333  0.2849462 0.3100000 1.424731    53
## [8]  {age=middle-age,                                                                           
##       married=YES}     => {income=average-income} 0.05833333  0.2671756 0.2183333 1.335878    35
## [9]  {children=0,                                                                               
##       car=YES}         => {income=average-income} 0.05500000  0.2661290 0.2066667 1.330645    33
## [10] {save_act=NO,                                                                              
##       mortgage=NO}     => {income=average-income} 0.05333333  0.2644628 0.2016667 1.322314    32
## [11] {age=middle-age}  => {income=average-income} 0.08500000  0.2615385 0.3250000 1.307692    51
## [12] {save_act=NO,                                                                              
##       current_act=YES} => {income=average-income} 0.05833333  0.2573529 0.2266667 1.286765    35
## [13] {age=middle-age,                                                                           
##       current_act=YES} => {income=average-income} 0.06166667  0.2569444 0.2400000 1.284722    37
## [14] {age=middle-age,                                                                           
##       mortgage=NO}     => {income=average-income} 0.05333333  0.2519685 0.2116667 1.259843    32
## [15] {sex=FEMALE,                                                                               
##       children=0}      => {income=average-income} 0.05500000  0.2500000 0.2200000 1.250000    33
inspectDT(avg_Income_rules[1:15])

Rule that is likely to result in a RHS “income=high-income”

high_Income_rules <- apriori(bank, parameter=list(supp=.05, conf=.25), 
                            appearance=list(default="lhs", rhs="income=high-income"),
                            control=list(verbose=F))
high_Income_rules
## set of 27 rules
high_Income_rules<- sort(high_Income_rules, by="lift", decreasing=TRUE)
inspect(high_Income_rules[1:15])
##      lhs                  rhs                     support confidence  coverage     lift count
## [1]  {age=middle-age,                                                                        
##       save_act=YES,                                                                          
##       current_act=YES} => {income=high-income} 0.06500000  0.3861386 0.1683333 1.930693    39
## [2]  {age=middle-age,                                                                        
##       save_act=YES}    => {income=high-income} 0.08166667  0.3769231 0.2166667 1.884615    49
## [3]  {age=middle-age,                                                                        
##       save_act=YES,                                                                          
##       mortgage=NO}     => {income=high-income} 0.05000000  0.3571429 0.1400000 1.785714    30
## [4]  {age=middle-age,                                                                        
##       pep=YES}         => {income=high-income} 0.05000000  0.3448276 0.1450000 1.724138    30
## [5]  {age=middle-age,                                                                        
##       current_act=YES} => {income=high-income} 0.08000000  0.3333333 0.2400000 1.666667    48
## [6]  {age=middle-age,                                                                        
##       car=YES}         => {income=high-income} 0.05000000  0.3157895 0.1583333 1.578947    30
## [7]  {age=old,                                                                               
##       car=YES}         => {income=high-income} 0.05833333  0.3097345 0.1883333 1.548673    35
## [8]  {age=middle-age,                                                                        
##       sex=MALE}        => {income=high-income} 0.05500000  0.3084112 0.1783333 1.542056    33
## [9]  {age=middle-age}  => {income=high-income} 0.10000000  0.3076923 0.3250000 1.538462    60
## [10] {age=middle-age,                                                                        
##       car=NO}          => {income=high-income} 0.05000000  0.3000000 0.1666667 1.500000    30
## [11] {sex=FEMALE,                                                                            
##       car=YES,                                                                               
##       current_act=YES} => {income=high-income} 0.05333333  0.2909091 0.1833333 1.454545    32
## [12] {sex=FEMALE,                                                                            
##       car=YES}         => {income=high-income} 0.06833333  0.2789116 0.2450000 1.394558    41
## [13] {age=middle-age,                                                                        
##       pep=NO}          => {income=high-income} 0.05000000  0.2777778 0.1800000 1.388889    30
## [14] {age=old,                                                                               
##       pep=YES}         => {income=high-income} 0.05333333  0.2758621 0.1933333 1.379310    32
## [15] {age=middle-age,                                                                        
##       mortgage=NO}     => {income=high-income} 0.05833333  0.2755906 0.2116667 1.377953    35
inspectDT(high_Income_rules[1:15])

Rule that is likely to result in a RHS “income=highest-income”

highest_Income_rules <- apriori(bank, parameter=list(supp=.05, conf=.25), 
                             appearance=list(default="lhs", rhs="income=highest-income"),
                             control=list(verbose=F))
highest_Income_rules
## set of 157 rules
highest_Income_rules<- sort(highest_Income_rules, by="lift", decreasing=TRUE)
inspect(highest_Income_rules[1:15])
##      lhs                  rhs                        support confidence   coverage     lift count
## [1]  {age=old,                                                                                   
##       children=0,                                                                                
##       save_act=YES,                                                                              
##       current_act=YES} => {income=highest-income} 0.05833333  0.7291667 0.08000000 3.645833    35
## [2]  {age=old,                                                                                   
##       married=YES,                                                                               
##       children=0,                                                                                
##       save_act=YES}    => {income=highest-income} 0.05166667  0.7045455 0.07333333 3.522727    31
## [3]  {age=old,                                                                                   
##       save_act=YES,                                                                              
##       mortgage=NO,                                                                               
##       pep=YES}         => {income=highest-income} 0.07333333  0.6984127 0.10500000 3.492063    44
## [4]  {age=old,                                                                                   
##       save_act=YES,                                                                              
##       current_act=YES,                                                                           
##       mortgage=NO,                                                                               
##       pep=YES}         => {income=highest-income} 0.05833333  0.6862745 0.08500000 3.431373    35
## [5]  {age=old,                                                                                   
##       car=NO,                                                                                    
##       save_act=YES,                                                                              
##       current_act=YES} => {income=highest-income} 0.06500000  0.6842105 0.09500000 3.421053    39
## [6]  {age=old,                                                                                   
##       sex=MALE,                                                                                  
##       save_act=YES,                                                                              
##       pep=YES}         => {income=highest-income} 0.05000000  0.6818182 0.07333333 3.409091    30
## [7]  {age=old,                                                                                   
##       save_act=YES,                                                                              
##       current_act=YES,                                                                           
##       pep=YES}         => {income=highest-income} 0.07500000  0.6818182 0.11000000 3.409091    45
## [8]  {age=old,                                                                                   
##       children=0,                                                                                
##       save_act=YES,                                                                              
##       pep=NO}          => {income=highest-income} 0.05333333  0.6808511 0.07833333 3.404255    32
## [9]  {age=old,                                                                                   
##       car=NO,                                                                                    
##       save_act=YES,                                                                              
##       mortgage=NO}     => {income=highest-income} 0.05666667  0.6800000 0.08333333 3.400000    34
## [10] {age=old,                                                                                   
##       children=0,                                                                                
##       save_act=YES}    => {income=highest-income} 0.07000000  0.6774194 0.10333333 3.387097    42
## [11] {age=old,                                                                                   
##       save_act=YES,                                                                              
##       pep=YES}         => {income=highest-income} 0.09833333  0.6704545 0.14666667 3.352273    59
## [12] {age=old,                                                                                   
##       married=YES,                                                                               
##       save_act=YES,                                                                              
##       pep=YES}         => {income=highest-income} 0.05666667  0.6666667 0.08500000 3.333333    34
## [13] {age=old,                                                                                   
##       married=YES,                                                                               
##       save_act=YES,                                                                              
##       current_act=YES} => {income=highest-income} 0.08666667  0.6666667 0.13000000 3.333333    52
## [14] {age=old,                                                                                   
##       sex=FEMALE,                                                                                
##       save_act=YES,                                                                              
##       current_act=YES,                                                                           
##       mortgage=NO}     => {income=highest-income} 0.05000000  0.6666667 0.07500000 3.333333    30
## [15] {age=old,                                                                                   
##       married=YES,                                                                               
##       save_act=YES,                                                                              
##       current_act=YES,                                                                           
##       mortgage=NO}     => {income=highest-income} 0.05500000  0.6470588 0.08500000 3.235294    33
inspectDT(highest_Income_rules[1:15])

Plot rules to copmare

plot(Lowest_Income_rules,  jitter=0)

plot(Low_Income_rules, jitter=0)

plot(avg_Income_rules, jitter=0)

plot(high_Income_rules, jitter=0)

plot(highest_Income_rules,jitter=0)

A customer in the “Old Age” bracket is likely to…

old_rules <- apriori (data=bank, parameter=list (supp=0.001,conf = 0.15,minlen=2), 
                  appearance = list(default="rhs",lhs="age=old"), control = list (verbose=F)) 
old_rules <- sort (old_rules, by="lift", decreasing=TRUE)
inspectDT((old_rules))

A customer in the “middle Age” bracket is likely to…

middle_age_rules <- apriori (data=bank, parameter=list (supp=0.001,conf = 0.15,minlen=2), 
                      appearance = list(default="rhs",lhs="age=middle-age"), control = list (verbose=F)) 
middle_age_rules <- sort (middle_age_rules, by="lift", decreasing=TRUE)
inspectDT((middle_age_rules))

A customer in the “young Age” bracket is likely to…

young_age_rules <- apriori (data=bank, parameter=list (supp=0.001,conf = 0.15,minlen=2), 
                             appearance = list(default="rhs",lhs="age=young"), control = list (verbose=F)) 
young_age_rules <- sort (young_age_rules, by="lift", decreasing=TRUE)
inspectDT((young_age_rules))