R Markdown

airline.df<-read.csv(paste("SixAirlinesDataV2.csv", sep=""))
summary(airline.df)
##       Airline      Aircraft   FlightDuration   TravelMonth
##  AirFrance: 74   AirBus:151   Min.   : 1.250   Aug:127    
##  British  :175   Boeing:307   1st Qu.: 4.260   Jul: 75    
##  Delta    : 46                Median : 7.790   Oct:127    
##  Jet      : 61                Mean   : 7.578   Sep:129    
##  Singapore: 40                3rd Qu.:10.620              
##  Virgin   : 62                Max.   :14.660              
##       IsInternational  SeatsEconomy    SeatsPremium    PitchEconomy  
##  Domestic     : 40    Min.   : 78.0   Min.   : 8.00   Min.   :30.00  
##  International:418    1st Qu.:133.0   1st Qu.:21.00   1st Qu.:31.00  
##                       Median :185.0   Median :36.00   Median :31.00  
##                       Mean   :202.3   Mean   :33.65   Mean   :31.22  
##                       3rd Qu.:243.0   3rd Qu.:40.00   3rd Qu.:32.00  
##                       Max.   :389.0   Max.   :66.00   Max.   :33.00  
##   PitchPremium    WidthEconomy    WidthPremium    PriceEconomy 
##  Min.   :34.00   Min.   :17.00   Min.   :17.00   Min.   :  65  
##  1st Qu.:38.00   1st Qu.:18.00   1st Qu.:19.00   1st Qu.: 413  
##  Median :38.00   Median :18.00   Median :19.00   Median :1242  
##  Mean   :37.91   Mean   :17.84   Mean   :19.47   Mean   :1327  
##  3rd Qu.:38.00   3rd Qu.:18.00   3rd Qu.:21.00   3rd Qu.:1909  
##  Max.   :40.00   Max.   :19.00   Max.   :21.00   Max.   :3593  
##   PricePremium    PriceRelative      SeatsTotal  PitchDifference 
##  Min.   :  86.0   Min.   :0.0200   Min.   : 98   Min.   : 2.000  
##  1st Qu.: 528.8   1st Qu.:0.1000   1st Qu.:166   1st Qu.: 6.000  
##  Median :1737.0   Median :0.3650   Median :227   Median : 7.000  
##  Mean   :1845.3   Mean   :0.4872   Mean   :236   Mean   : 6.688  
##  3rd Qu.:2989.0   3rd Qu.:0.7400   3rd Qu.:279   3rd Qu.: 7.000  
##  Max.   :7414.0   Max.   :1.8900   Max.   :441   Max.   :10.000  
##  WidthDifference PercentPremiumSeats
##  Min.   :0.000   Min.   : 4.71      
##  1st Qu.:1.000   1st Qu.:12.28      
##  Median :1.000   Median :13.21      
##  Mean   :1.633   Mean   :14.65      
##  3rd Qu.:3.000   3rd Qu.:15.36      
##  Max.   :4.000   Max.   :24.69

Including Plots

The main point of using the seed is to be able to reproduce a particular sequence of ‘random’ numbers. The seed number you choose is the starting point used in the generation of a sequence of random numbers, which is why (provided you use the same pseudo-random number generator) you’ll obtain the same results given the same seed number.

Splitting ratio: if (0<=splitratio<1)< code=“”> then SplitRatio fraction of points from Y will be set toTRUE if (SplitRatio==1) then one random point from Y will be set to TRUE if (SplitRatio>1) then SplitRatio number of points from Y will be set to TRUE

## Warning: package 'caTools' was built under R version 3.4.3
##       Airline Aircraft FlightDuration TravelMonth IsInternational
## 2     British   Boeing          12.25         Aug   International
## 15    British   Boeing          11.58         Sep   International
## 16    British   Boeing          11.58         Oct   International
## 19    British   Boeing           9.16         Oct   International
## 26    British   Boeing           8.75         Aug   International
## 28    British   Boeing           8.75         Oct   International
## 37    British   Boeing          13.50         Sep   International
## 42    British   Boeing           3.83         Oct   International
## 50    British   Boeing          12.75         Sep   International
## 53    British   Boeing          11.08         Aug   International
## 54    British   Boeing          11.08         Sep   International
## 55    British   Boeing          11.08         Oct   International
## 56    British   Boeing           6.08         Aug   International
## 61    British   Boeing          12.50         Oct   International
## 64     Virgin   AirBus           8.00         Sep   International
## 73     Virgin   AirBus           7.75         Aug   International
## 78      Delta   Boeing           2.33         Oct        Domestic
## 83    British   Boeing           6.83         Aug   International
## 85    British   Boeing           6.83         Oct   International
## 87    British   Boeing           7.58         Sep   International
## 94        Jet   Boeing           3.08         Aug   International
## 101   British   AirBus          11.16         Sep   International
## 102   British   AirBus          11.16         Oct   International
## 103   British   AirBus          10.50         Jul   International
## 108   British   AirBus          13.08         Sep   International
## 110   British   AirBus          11.16         Sep   International
## 114   British   AirBus           3.58         Aug   International
## 115   British   AirBus           3.58         Sep   International
## 119   British   AirBus           3.58         Aug   International
## 123   British   AirBus           2.41         Aug   International
## 124   British   AirBus           3.25         Oct   International
## 130   British   AirBus           1.83         Aug   International
## 144   British   Boeing           1.25         Sep   International
## 146   British   AirBus           2.83         Oct   International
## 151   British   Boeing           1.33         Oct   International
## 153     Delta   Boeing           4.51         Aug        Domestic
## 154     Delta   Boeing           4.33         Jul        Domestic
## 155     Delta   Boeing           4.51         Jul        Domestic
## 160    Virgin   Boeing          12.08         Aug   International
## 165    Virgin   Boeing           9.91         Aug   International
## 166    Virgin   Boeing           9.91         Sep   International
## 169    Virgin   Boeing          10.83         Aug   International
## 170    Virgin   Boeing          10.83         Sep   International
## 173    Virgin   Boeing          12.58         Aug   International
## 175    Virgin   Boeing          10.75         Aug   International
## 177    Virgin   Boeing          10.75         Oct   International
## 179    Virgin   Boeing          11.33         Oct   International
## 184    Virgin   Boeing          12.58         Sep   International
## 194    Virgin   AirBus           6.91         Oct   International
## 196    Virgin   AirBus           6.58         Aug   International
## 201    Virgin   AirBus          10.41         Sep   International
## 210    Virgin   AirBus           7.75         Sep   International
## 217 AirFrance   AirBus           8.33         Sep   International
## 218 AirFrance   AirBus           8.33         Oct   International
## 220 AirFrance   AirBus           8.33         Aug   International
## 221 AirFrance   AirBus           8.33         Sep   International
## 227 AirFrance   AirBus           6.83         Oct   International
## 231 AirFrance   AirBus           8.08         Sep   International
## 240   British   Boeing          10.41         Aug   International
## 246   British   Boeing           9.91         Jul   International
## 252   British   Boeing           8.58         Oct   International
## 261   British   Boeing           8.66         Aug   International
## 262   British   Boeing           8.66         Sep   International
## 265   British   Boeing           7.25         Sep   International
## 268   British   Boeing           7.08         Aug   International
## 270   British   Boeing           7.08         Oct   International
## 278   British   Boeing          11.08         Sep   International
## 283     Delta   Boeing           4.63         Aug        Domestic
## 284     Delta   Boeing           4.65         Sep        Domestic
## 285     Delta   Boeing           4.66         Oct        Domestic
## 286     Delta   Boeing           4.70         Jul        Domestic
## 289     Delta   Boeing           4.36         Sep        Domestic
## 296     Delta   AirBus           1.95         Sep        Domestic
## 297     Delta   AirBus           2.26         Sep        Domestic
## 298     Delta   AirBus           2.55         Oct        Domestic
## 313       Jet   AirBus           9.50         Sep   International
## 314       Jet   AirBus           8.91         Aug   International
## 320 Singapore   Boeing          12.41         Sep   International
## 321 Singapore   Boeing          12.41         Oct   International
## 325 Singapore   Boeing          14.66         Aug   International
## 331 Singapore   Boeing           3.83         Jul   International
## 333 Singapore   Boeing           3.83         Sep   International
## 336 Singapore   Boeing          12.75         Sep   International
## 342 AirFrance   Boeing           7.50         Oct   International
## 343 AirFrance   Boeing           6.83         Aug   International
## 353 AirFrance   Boeing           9.50         Oct   International
## 355 AirFrance   Boeing           7.75         Aug   International
## 358 AirFrance   Boeing           9.41         Aug   International
## 360 AirFrance   Boeing           9.41         Oct   International
## 364 AirFrance   Boeing          11.91         Aug   International
## 367   British   Boeing          13.83         Aug   International
## 370   British   Boeing          13.33         Aug   International
## 372   British   Boeing          13.33         Oct   International
## 377   British   Boeing           9.58         Oct   International
## 383       Jet   Boeing           3.25         Oct   International
## 389       Jet   Boeing           2.50         Oct   International
## 390       Jet   Boeing           2.66         Jul   International
## 396       Jet   Boeing           4.16         Oct   International
## 399       Jet   Boeing           2.66         Aug   International
## 405       Jet   Boeing           3.25         Jul   International
## 407 AirFrance   Boeing           6.91         Oct   International
## 410 Singapore   AirBus          13.33         Jul   International
## 418 Singapore   AirBus          12.66         Jul   International
## 423 Singapore   AirBus           6.50         Aug   International
## 424 Singapore   AirBus           6.50         Sep   International
## 426 AirFrance   AirBus          13.00         Sep   International
## 432 AirFrance   Boeing          10.66         Oct   International
## 435 AirFrance   AirBus           8.50         Sep   International
## 436 AirFrance   Boeing           8.50         Oct   International
## 441       Jet   Boeing           3.16         Jul   International
## 443       Jet   Boeing           5.66         Jul   International
## 444       Jet   Boeing           5.66         Aug   International
## 447       Jet   Boeing           5.66         Jul   International
## 450       Jet   Boeing           2.58         Sep   International
## 453       Jet   Boeing           2.58         Jul   International
##     SeatsEconomy SeatsPremium PitchEconomy PitchPremium WidthEconomy
## 2            122           40           31           38           18
## 15           122           40           31           38           18
## 16           122           40           31           38           18
## 19           122           40           31           38           18
## 26           122           40           31           38           18
## 28           122           40           31           38           18
## 37           122           40           31           38           18
## 42           122           40           31           38           18
## 50           122           40           31           38           18
## 53           127           39           31           38           18
## 54           127           39           31           38           18
## 55           127           39           31           38           18
## 56           127           39           31           38           18
## 61           127           39           31           38           18
## 64           185           48           31           38           18
## 73           185           48           31           38           18
## 78            78           20           31           34           18
## 83           243           56           31           38           18
## 85           243           56           31           38           18
## 87           243           56           31           38           18
## 94           138           28           30           40           17
## 101          303           55           31           38           18
## 102          303           55           31           38           18
## 103          303           55           31           38           18
## 108          303           55           31           38           18
## 110          303           55           31           38           18
## 114          303           55           31           38           18
## 115          303           55           31           38           18
## 119          303           55           31           38           18
## 123          303           55           31           38           18
## 124          303           55           31           38           18
## 130          303           55           31           38           18
## 144          303           55           31           38           18
## 146          303           55           31           38           18
## 151          303           55           31           38           18
## 153          171           29           32           35           18
## 154          171           29           32           35           18
## 155          171           29           32           35           18
## 160          198           35           31           38           18
## 165          375           66           31           38           18
## 166          375           66           31           38           18
## 169          198           35           31           38           18
## 170          198           35           31           38           18
## 173          198           35           31           38           18
## 175          375           66           31           38           18
## 177          375           66           31           38           18
## 179          198           35           31           38           18
## 184          198           35           31           38           18
## 194          233           38           31           38           18
## 196          233           38           31           38           18
## 201          233           38           31           38           18
## 210          233           38           31           38           18
## 217          147           21           32           38           18
## 218          147           21           32           38           18
## 220          147           21           32           38           18
## 221          147           21           32           38           18
## 227          147           21           32           38           18
## 231          147           21           32           38           18
## 240          243           36           31           38           18
## 246          243           36           31           38           18
## 252          243           36           31           38           18
## 261          243           36           31           38           18
## 262          243           36           31           38           18
## 265          243           36           31           38           18
## 268          243           36           31           38           18
## 270          243           36           31           38           18
## 278          243           36           31           38           18
## 283          126           18           32           34           17
## 284          126           18           32           34           17
## 285          126           18           32           34           17
## 286          139           21           31           34           17
## 289          126           18           32           34           17
## 296          120           18           32           34           17
## 297          120           18           32           34           17
## 298          136           20           33           35           17
## 313          147           21           32           38           18
## 314          147           21           32           38           18
## 320          184           28           32           38           19
## 321          184           28           32           38           19
## 325          184           28           32           38           19
## 331          184           28           32           38           19
## 333          184           28           32           38           19
## 336          184           28           32           38           19
## 342          200           28           32           38           17
## 343          200           28           32           38           17
## 353          200           28           32           38           17
## 355          174           24           32           38           17
## 358          200           28           32           38           17
## 360          200           28           32           38           17
## 364          200           28           32           38           17
## 367          203           24           31           38           18
## 370          203           24           31           38           18
## 372          203           24           31           38           18
## 377          203           24           31           38           18
## 383          124           16           30           40           17
## 389          124           16           30           40           17
## 390          124           16           30           40           17
## 396          124           16           30           40           17
## 399          124           16           30           40           17
## 405          124           16           30           40           17
## 407          216           24           32           38           17
## 410          333           36           32           38           19
## 418          333           36           32           38           19
## 423          333           36           32           38           19
## 424          333           36           32           38           19
## 426          389           38           32           38           18
## 432          389           38           32           38           18
## 435          389           38           32           38           18
## 436          389           38           32           38           18
## 441          162            8           30           40           17
## 443          162            8           30           40           17
## 444          162            8           30           40           17
## 447          162            8           30           40           17
## 450          162            8           30           40           17
## 453          162            8           30           40           17
##     WidthPremium PriceEconomy PricePremium PriceRelative SeatsTotal
## 2             19         2707         3725          0.38        162
## 15            19         1750         2656          0.52        162
## 16            19         1750         2656          0.52        162
## 19            19         1813         2504          0.38        162
## 26            19         1542         2084          0.35        162
## 28            19         1566         2084          0.33        162
## 37            19          940         1548          0.65        162
## 42            19         1224         1512          0.24        162
## 50            19          509          773          0.52        162
## 53            19         2156         2933          0.36        166
## 54            19         2156         2933          0.36        166
## 55            19         2156         2933          0.36        166
## 56            19         1634         2195          0.34        166
## 61            19          509          818          0.61        166
## 64            21         1813         3128          0.73        233
## 73            21          540          594          0.10        233
## 78            18          216          231          0.07         98
## 83            19         1444         2982          1.07        299
## 85            19         1444         2982          1.07        299
## 87            19         1824         2549          0.40        299
## 94            21          464          616          0.33        166
## 101           19         2384         3563          0.49        358
## 102           19         2384         3563          0.49        358
## 103           19         1848         3536          0.91        358
## 108           19         1758         2592          0.47        358
## 110           19          719         1634          1.27        358
## 114           19          402          442          0.10        358
## 115           19          402          442          0.10        358
## 119           19          322          348          0.08        358
## 123           19          276          306          0.11        358
## 124           19          249          285          0.14        358
## 130           19          201          237          0.18        358
## 144           19          109          141          0.30        358
## 146           19           97          125          0.29        358
## 151           19           65           86          0.33        358
## 153           18          423          467          0.10        200
## 154           18          483          527          0.09        200
## 155           18          713          757          0.06        200
## 160           21         1086         2964          1.73        233
## 165           21         1781         3509          0.97        441
## 166           21         1781         3509          0.97        441
## 169           21         1580         3019          0.91        233
## 170           21         1580         3019          0.91        233
## 173           21         1096         1710          0.56        233
## 175           21         2445         3694          0.51        441
## 177           21         2445         3694          0.51        441
## 179           21         2369         3540          0.49        233
## 184           21         1356         1710          0.26        233
## 194           21         1434         2982          1.08        271
## 196           21         1476         2997          1.03        271
## 201           21         1903         3509          0.84        271
## 210           21          540          594          0.10        271
## 217           19         2659         2859          0.08        168
## 218           19         2659         2859          0.08        168
## 220           19         2659         2859          0.08        168
## 221           19         2659         2859          0.08        168
## 227           19         2860         3063          0.07        168
## 231           19         2813         2922          0.04        168
## 240           19         1651         3509          1.13        279
## 246           19         2356         3200          0.36        279
## 252           19         1562         3099          0.98        279
## 261           19         1609         2292          0.42        279
## 262           19         1609         2292          0.42        279
## 265           19         1632         2278          0.40        279
## 268           19         1736         1866          0.07        279
## 270           19         1736         1866          0.07        279
## 278           19         1023         1199          0.17        279
## 283           17          363          407          0.12        144
## 284           17          363          407          0.12        144
## 285           17          363          407          0.12        144
## 286           17          413          457          0.11        160
## 289           17          413          457          0.11        144
## 296           17          166          181          0.09        138
## 297           17          329          354          0.08        138
## 298           17          243          262          0.08        156
## 313           19          661          928          0.40        168
## 314           19          676          931          0.38        168
## 320           20         1215         1947          0.60        212
## 321           20         1215         1947          0.60        212
## 325           20         1406         1584          0.13        212
## 331           20          563          619          0.10        212
## 333           20          563          619          0.10        212
## 336           20         1431         1564          0.09        212
## 342           19         2581         2781          0.08        228
## 343           19         2860         3063          0.07        228
## 353           19         3414         3524          0.03        228
## 355           19         3215         3325          0.03        198
## 358           19         3480         3589          0.03        228
## 360           19         3480         3589          0.03        228
## 364           19         3159         3243          0.03        228
## 367           19         3102         7414          1.39        227
## 370           19         2166         2470          0.14        227
## 372           19         2166         2470          0.14        227
## 377           19          524          797          0.52        227
## 383           21          149          398          1.67        140
## 389           21          118          267          1.26        140
## 390           21          108          228          1.11        140
## 396           21          156          318          1.04        140
## 399           21          127          228          0.79        140
## 405           21          594          696          0.17        140
## 407           19          648         1710          1.64        240
## 410           20          505         1004          0.99        369
## 418           20          690         1110          0.61        369
## 423           20          690         1110          0.61        369
## 424           20          690         1110          0.61        369
## 426           19         1522         3289          1.16        427
## 432           19         2996         3196          0.07        427
## 435           19         2979         3088          0.04        427
## 436           19         2979         3088          0.04        427
## 441           21          148          397          1.68        170
## 443           21          187          430          1.30        170
## 444           21          187          430          1.30        170
## 447           21          245          545          1.22        170
## 450           21          172          304          0.77        170
## 453           21          281          451          0.60        170
##     PitchDifference WidthDifference PercentPremiumSeats
## 2                 7               1               24.69
## 15                7               1               24.69
## 16                7               1               24.69
## 19                7               1               24.69
## 26                7               1               24.69
## 28                7               1               24.69
## 37                7               1               24.69
## 42                7               1               24.69
## 50                7               1               24.69
## 53                7               1               23.49
## 54                7               1               23.49
## 55                7               1               23.49
## 56                7               1               23.49
## 61                7               1               23.49
## 64                7               3               20.60
## 73                7               3               20.60
## 78                3               0               20.41
## 83                7               1               18.73
## 85                7               1               18.73
## 87                7               1               18.73
## 94               10               4               16.87
## 101               7               1               15.36
## 102               7               1               15.36
## 103               7               1               15.36
## 108               7               1               15.36
## 110               7               1               15.36
## 114               7               1               15.36
## 115               7               1               15.36
## 119               7               1               15.36
## 123               7               1               15.36
## 124               7               1               15.36
## 130               7               1               15.36
## 144               7               1               15.36
## 146               7               1               15.36
## 151               7               1               15.36
## 153               3               0               14.50
## 154               3               0               14.50
## 155               3               0               14.50
## 160               7               3               15.02
## 165               7               3               14.97
## 166               7               3               14.97
## 169               7               3               15.02
## 170               7               3               15.02
## 173               7               3               15.02
## 175               7               3               14.97
## 177               7               3               14.97
## 179               7               3               15.02
## 184               7               3               15.02
## 194               7               3               14.02
## 196               7               3               14.02
## 201               7               3               14.02
## 210               7               3               14.02
## 217               6               1               12.50
## 218               6               1               12.50
## 220               6               1               12.50
## 221               6               1               12.50
## 227               6               1               12.50
## 231               6               1               12.50
## 240               7               1               12.90
## 246               7               1               12.90
## 252               7               1               12.90
## 261               7               1               12.90
## 262               7               1               12.90
## 265               7               1               12.90
## 268               7               1               12.90
## 270               7               1               12.90
## 278               7               1               12.90
## 283               2               0               12.50
## 284               2               0               12.50
## 285               2               0               12.50
## 286               3               0               13.13
## 289               2               0               12.50
## 296               2               0               13.04
## 297               2               0               13.04
## 298               2               0               12.82
## 313               6               1               12.50
## 314               6               1               12.50
## 320               6               1               13.21
## 321               6               1               13.21
## 325               6               1               13.21
## 331               6               1               13.21
## 333               6               1               13.21
## 336               6               1               13.21
## 342               6               2               12.28
## 343               6               2               12.28
## 353               6               2               12.28
## 355               6               2               12.12
## 358               6               2               12.28
## 360               6               2               12.28
## 364               6               2               12.28
## 367               7               1               10.57
## 370               7               1               10.57
## 372               7               1               10.57
## 377               7               1               10.57
## 383              10               4               11.43
## 389              10               4               11.43
## 390              10               4               11.43
## 396              10               4               11.43
## 399              10               4               11.43
## 405              10               4               11.43
## 407               6               2               10.00
## 410               6               1                9.76
## 418               6               1                9.76
## 423               6               1                9.76
## 424               6               1                9.76
## 426               6               1                8.90
## 432               6               1                8.90
## 435               6               1                8.90
## 436               6               1                8.90
## 441              10               4                4.71
## 443              10               4                4.71
## 444              10               4                4.71
## 447              10               4                4.71
## 450              10               4                4.71
## 453              10               4                4.71

NUll deviation=deviation of model with nothing but intercept Residual deviation=deviation of overall model with independent variables, hence lower degrees of freedom, difference in degrees=no of independent variables

model<-glm(Aircraft~.-TravelMonth, data=train, family = binomial) #all_parameters_except_travel_month
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
summary(model)
## 
## Call:
## glm(formula = Aircraft ~ . - TravelMonth, family = binomial, 
##     data = train)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.65903  -0.48889   0.00001   0.32806   2.80871  
## 
## Coefficients: (3 not defined because of singularities)
##                                Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                  -6.545e+02  7.207e+05  -0.001  0.99928   
## AirlineBritish               -1.347e+01  1.975e+04  -0.001  0.99946   
## AirlineDelta                 -8.807e+01  5.460e+04  -0.002  0.99871   
## AirlineJet                   -1.705e+02  7.700e+04  -0.002  0.99823   
## AirlineSingapore              5.617e+00  2.715e+04   0.000  0.99983   
## AirlineVirgin                -6.523e+01  4.876e+04  -0.001  0.99893   
## FlightDuration                1.588e-01  8.808e-02   1.803  0.07144 . 
## IsInternationalInternational -2.842e+02  1.137e+05  -0.002  0.99801   
## SeatsEconomy                  1.867e-02  1.074e-02   1.738  0.08213 . 
## SeatsPremium                 -2.340e-01  7.437e-02  -3.146  0.00166 **
## PitchEconomy                 -2.057e+01  1.975e+04  -0.001  0.99917   
## PitchPremium                  4.165e+01  2.655e+04   0.002  0.99875   
## WidthEconomy                 -2.568e+01  1.224e+04  -0.002  0.99833   
## WidthPremium                  2.455e+01  2.978e+04   0.001  0.99934   
## PriceEconomy                  2.384e-03  1.401e-03   1.702  0.08880 . 
## PricePremium                 -1.255e-03  8.830e-04  -1.421  0.15535   
## PriceRelative                 1.639e+00  1.109e+00   1.478  0.13937   
## SeatsTotal                           NA         NA      NA       NA   
## PitchDifference                      NA         NA      NA       NA   
## WidthDifference                      NA         NA      NA       NA   
## PercentPremiumSeats           4.605e-01  2.057e-01   2.239  0.02515 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 438.92  on 342  degrees of freedom
## Residual deviance: 194.33  on 325  degrees of freedom
## AIC: 230.33
## 
## Number of Fisher Scoring iterations: 22

p = exp(??o + ??(x)) / exp(??o + ??(x)) + 1 = e^(??o + ??(Age)) / e^(??o + ??(x)) + 1 q=1-p=probability of failure odds ratio=p/(1-p) logit(p)=log(p/(1-p))=??o + ??(x), here p=dependent variable like y Regression model finds best fit values for coefficients to ensure linear relationship between logit(y) and x. type=‘response’ returns p or y; by default it returns logit(p) or y of linear regression

predict<-predict(model, type='response', newdata=test)
## Warning in predict.lm(object, newdata, se.fit, scale = 1, type =
## ifelse(type == : prediction from a rank-deficient fit may be misleading
predict
##            2           15           16           19           26 
## 9.973313e-01 9.939776e-01 9.939776e-01 9.921042e-01 9.900494e-01 
##           28           37           42           50           53 
## 9.902874e-01 9.938380e-01 9.733575e-01 9.909502e-01 9.942894e-01 
##           54           55           56           61           64 
## 9.942894e-01 9.942894e-01 9.822685e-01 9.892484e-01 3.078632e-01 
##           73           78           83           85           87 
## 1.496081e-01 1.000000e+00 4.714092e-01 4.714092e-01 5.880661e-01 
##           94          101          102          103          108 
## 1.000000e+00 7.184494e-01 7.184494e-01 5.686158e-01 7.180336e-01 
##          110          114          115          119          123 
## 6.605312e-01 1.524975e-01 1.524975e-01 1.393497e-01 1.177114e-01 
##          124          130          144          146          151 
## 1.335676e-01 1.106709e-01 1.112283e-01 1.356021e-01 1.138214e-01 
##          153          154          155          160          165 
## 1.000000e+00 1.000000e+00 1.000000e+00 6.599607e-01 1.936220e-02 
##          166          169          170          173          175 
## 1.936220e-02 5.571866e-01 5.571866e-01 6.041045e-01 3.937910e-02 
##          177          179          184          194          196 
## 3.937910e-02 7.002070e-01 6.343409e-01 2.839932e-01 2.733379e-01 
##          201          210          217          218          220 
## 4.242463e-01 1.776512e-01 1.168365e-01 1.168365e-01 1.168365e-01 
##          221          227          231          240          246 
## 1.168365e-01 1.136446e-01 1.370666e-01 9.151911e-01 9.571441e-01 
##          252          261          262          265          268 
## 8.951653e-01 9.140646e-01 9.140646e-01 8.984445e-01 9.150729e-01 
##          270          278          283          284          285 
## 9.150729e-01 9.099647e-01 8.073080e-01 8.078015e-01 8.080479e-01 
##          286          289          296          297          298 
## 1.000000e+00 8.068743e-01 7.126952e-01 7.526672e-01 1.000000e+00 
##          313          314          320          321          325 
## 2.220446e-16 2.220446e-16 7.397726e-01 7.397726e-01 8.238587e-01 
##          331          333          336          342          343 
## 2.640567e-01 2.640567e-01 7.787856e-01 1.000000e+00 1.000000e+00 
##          353          355          358          360          364 
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 
##          367          370          372          377          383 
## 9.476092e-01 9.913306e-01 9.913306e-01 9.503076e-01 1.000000e+00 
##          389          390          396          399          405 
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 
##          407          410          418          423          424 
## 1.000000e+00 6.551036e-01 5.549211e-01 3.191924e-01 3.191924e-01 
##          426          432          435          436          441 
## 2.025119e-02 8.272700e-02 6.279678e-02 6.279678e-02 1.000000e+00 
##          443          444          447          450          453 
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00

Airbus is false and Boeing is true. Hence, 96 times where Airbus was there was predicted correvtly while 20 times in which Airbus was there was predicted wrongly. TRUE POSITIVE=PREDICTED TRUE CORRECTLY TRUE NEGATIVE=PREDICTED FALSE CORRECTLY Cannot use table directly as table[1,1] as table already inbuilt function and cannot be used as object internally, which leads to closure. c=Accuracy=(TRUE POSITIVE+TRUE NEGATIVE)/(TP+TN+FN+FP) pre=Precision=(TRUE POSITIVE)/(TP+TN) re=recall=TP/(TP+FN)=TPR=Sensitivity spe=TNR=Specificity=(TN)/(TN+FP)

summary(test$Aircraft)
## AirBus Boeing 
##     35     80
t<-table(test$Aircraft, predict>0.5)
t
##         
##          FALSE TRUE
##   AirBus    25   10
##   Boeing    12   68
t[1,1]
## [1] 25
acc=(t[1,1]+t[2,2])/sum(t)
acc
## [1] 0.8086957
pre=t[2,2]/(t[1,2]+t[2,2])
pre
## [1] 0.8717949
re=t[2,2]/(t[2,2]+t[2,1])
re
## [1] 0.85
spe=t[1,1]/(t[1,1]+t[1,2])
spe
## [1] 0.7142857

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.