Assignment_2_Rishabh_arora

docx

School

Conestoga College *

*We aren’t endorsed by this school

Course

8010

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

29

Uploaded by UltraWater15179

Report
Assignment_2_Rishabh_arora.R Rishabh Arora 2024-02-13 library (readxl) library (pROC) ## Type 'citation("pROC")' for a citation. ## ## Attaching package: 'pROC' ## The following objects are masked from 'package:stats': ## ## cov, smooth, var library (dplyr) ## ## Attaching package: 'dplyr' ## The following objects are masked from 'package:stats': ## ## filter, lag ## The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union library (caret) ## Loading required package: ggplot2 ## Loading required package: lattice library (glmnet) ## Warning: package 'glmnet' was built under R version 4.3.2 ## Loading required package: Matrix ## Warning: package 'Matrix' was built under R version 4.3.2 ## Loaded glmnet 4.1-8 library (randomForest) ## Warning: package 'randomForest' was built under R version 4.3.2 ## randomForest 4.7-1.1
## Type rfNews() to see new features/changes/bug fixes. ## ## Attaching package: 'randomForest' ## The following object is masked from 'package:ggplot2': ## ## margin ## The following object is masked from 'package:dplyr': ## ## combine file_path <- "C:/Users/Rishabh Arora/Downloads/grey.xlsx" sheet_names <- excel_sheets (file_path) greydata <- read_excel (file_path, sheet = sheet_names[ 2 ]) head (greydata) ## # A tibble: 6 × 38 ## CustomerID Age HomeOwner ResidenceLength DwellingType Gender Marital ## <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> ## 1 1 70 10 1 M F M ## 2 2 65 10 4 M F S ## 3 3 76 10 1 M F M ## 4 4 54 10 1 M F S ## 5 5 78 10 7 M M M ## 6 6 40 10 1 M F M ## # 31 more variables: HouseholdSize <dbl>, ChildPresent <chr>, Child0.5 <dbl>, ## # Child6.12 <dbl>, Child13.18 <dbl>, Income <dbl>, Occupation <chr>, ## # HomeValue <dbl>, MagazineStatus <chr>, PaidDirectMailOrders <dbl>, ## # YearsSinceLastOrder <dbl>, TotalAmountPaid <dbl>, DollarsPerIssue <dbl>, ## # TotalPaidOrders <dbl>, MonthsSinceLastPayment <dbl>, LastPaymentType <chr>, ## # UnpaidMagazines <dbl>, PaidCashMagazines <dbl>, ## # PaidReinstateMagazines <dbl>, PaidCreditMagazines <dbl>, … str (greydata)
## tibble [42,077 × 38] (S3: tbl_df/tbl/data.frame) ## $ CustomerID : num [1:42077] 1 2 3 4 5 6 7 8 9 10 ... ## $ Age : num [1:42077] 70 65 76 54 78 40 60 27 42 24 ... ## $ HomeOwner : num [1:42077] 10 10 10 10 10 10 10 10 10 10 ... ## $ ResidenceLength : num [1:42077] 1 4 1 1 7 1 5 1 13 2 ... ## $ DwellingType : chr [1:42077] "M" "M" "M" "M" ... ## $ Gender : chr [1:42077] "F" "F" "F" "F" ... ## $ Marital : chr [1:42077] "M" "S" "M" "S" ... ## $ HouseholdSize : num [1:42077] 3 1 2 1 2 2 1 1 1 2 ... ## $ ChildPresent : chr [1:42077] "Y" "U" "N" "U" ... ## $ Child0.5 : num [1:42077] 45 35 25 0 35 65 15 45 15 15 ... ## $ Child6.12 : num [1:42077] 35 15 15 15 15 55 35 15 15 25 ... ## $ Child13.18 : num [1:42077] 100 35 25 0 15 85 15 15 15 15 ... ## $ Income : num [1:42077] 29000 13000 36000 23000 5000 30000 144000 5000 20000 24000 ... ## $ Occupation : chr [1:42077] "R" "M" "U" "M" ... ## $ HomeValue : num [1:42077] 4 8 7 3 9 2 5 5 9 4 ... ## $ MagazineStatus : chr [1:42077] "B" "E" "E" "E" ... ## $ PaidDirectMailOrders : num [1:42077] 2 1 3 0 0 0 0 0 0 0 ... ## $ YearsSinceLastOrder : num [1:42077] 8 4 3 5 3 4 0 4 3 3 ... ## $ TotalAmountPaid : num [1:42077] 50 40 60 41.5 97 ... ## $ DollarsPerIssue : num [1:42077] 0.36 0.48 0.62 0.38 1.47 0.61 0 0 0.92 0.67 ... ## $ TotalPaidOrders : num [1:42077] 3 4 3 3 4 2 1 1 1 2 ... ## $ MonthsSinceLastPayment: num [1:42077] 89 39 53 68 37 59 60 55 50 47 ... ## $ LastPaymentType : chr [1:42077] "0" "A" "1" "2" ... ## $ UnpaidMagazines : num [1:42077] 3 0 0 0 0 0 0 0 0 0 ... ## $ PaidCashMagazines : num [1:42077] 2 2 0 0 2 2 1 1 1 2 ... ## $ PaidReinstateMagazines: num [1:42077] 0 0 0 0 0 0 0 0 0 0 ... ## $ PaidCreditMagazines : num [1:42077] 0 0 2 1 0 0 0 0 0 0 ... ## $ ActiveSubscriptions : num [1:42077] 0 0 0 0 0 0 0 0 0 0 ... ## $ ExpiredSubscriptions : num [1:42077] 2 2 2 1 1 2 1 1 1 2 ... ## $ RequestedCancellations: num [1:42077] 0 0 0 0 0 0 0 0 0 0 ... ## $ NoPayCancellations : num [1:42077] 3 0 0 0 1 0 0 0 0 0 ... ## $ PaidComplaints : num [1:42077] 0 0 0 0 0 0 0 0 0 0 ... ## $ GiftDonor : chr [1:42077] "N" "Y" "N" "N" ... ## $ NumberGiftDonations : num [1:42077] 0 2 0 0 0 0 0 0 0 0 ... ## $ MonthsSince1stOrder : num [1:42077] 118 90 91 158 50 59 60 55 50 47 ... ## $ MonthsSinceLastOrder : num [1:42077] 89 90 54 60 37 59 60 55 50 47 ... ## $ MonthsSinceExpire : num [1:42077] 52 52 17 20 34 46 47 42 25 34 ... ## $ Renewal : chr [1:42077] "No" "No" "No" "No" ...
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
summary (greydata) ## CustomerID Age HomeOwner ResidenceLength ## Min. : 1 Min. :18.00 Min. : 0.00 Min. : 1.000 ## 1st Qu.:10520 1st Qu.:42.00 1st Qu.:100.00 1st Qu.: 4.000 ## Median :21039 Median :52.00 Median :100.00 Median : 9.000 ## Mean :21039 Mean :51.64 Mean : 89.23 Mean : 8.525 ## 3rd Qu.:31558 3rd Qu.:62.00 3rd Qu.:100.00 3rd Qu.:14.000 ## Max. :42077 Max. :84.00 Max. :100.00 Max. :14.000 ## DwellingType Gender Marital HouseholdSize ## Length:42077 Length:42077 Length:42077 Min. :1.00 ## Class :character Class :character Class :character 1st Qu.:2.00 ## Mode :character Mode :character Mode :character Median :3.00 ## Mean :3.16 ## 3rd Qu.:4.00 ## Max. :6.00 ## ChildPresent Child0.5 Child6.12 Child13.18 ## Length:42077 Min. : 0.00 Min. : 0.00 Min. : 0.00 ## Class :character 1st Qu.: 15.00 1st Qu.: 0.00 1st Qu.: 25.00 ## Mode :character Median : 45.00 Median : 35.00 Median : 45.00 ## Mean : 43.49 Mean : 43.06 Mean : 50.58 ## 3rd Qu.: 65.00 3rd Qu.:100.00 3rd Qu.:100.00 ## Max. :100.00 Max. :100.00 Max. :100.00 ## Income Occupation HomeValue MagazineStatus ## Min. : 5000 Length:42077 Min. :1.000 Length:42077 ## 1st Qu.: 42500 Class :character 1st Qu.:3.000 Class :character ## Median : 78000 Mode :character Median :4.000 Mode :character ## Mean : 91223 Mean :4.365 ## 3rd Qu.:122000 3rd Qu.:6.000 ## Max. :500000 Max. :9.000
## PaidDirectMailOrders YearsSinceLastOrder TotalAmountPaid DollarsPerIssue ## Min. : 0.0000 Min. : 0.000 Min. : 0.00 Min. :0.0000 ## 1st Qu.: 0.0000 1st Qu.: 3.000 1st Qu.: 19.00 1st Qu.:0.5200 ## Median : 0.0000 Median : 5.000 Median : 40.00 Median :0.7100 ## Mean : 0.8113 Mean : 5.332 Mean : 59.41 Mean :0.7511 ## 3rd Qu.: 1.0000 3rd Qu.: 8.000 3rd Qu.: 80.91 3rd Qu.:0.9200 ## Max. :16.0000 Max. :15.000 Max. :1304.73 Max. :5.0000 ## TotalPaidOrders MonthsSinceLastPayment LastPaymentType UnpaidMagazines ## Min. : 0.000 Min. : 0.00 Length:42077 Min. : 0.00 ## 1st Qu.: 1.000 1st Qu.: 32.00 Class :character 1st Qu.: 0.00 ## Median : 2.000 Median : 57.00 Mode :character Median : 0.00 ## Mean : 3.762 Mean : 60.44 Mean : 0.21 ## 3rd Qu.: 5.000 3rd Qu.: 88.00 3rd Qu.: 0.00 ## Max. :109.000 Max. :312.00 Max. :10.00 ## PaidCashMagazines PaidReinstateMagazines PaidCreditMagazines ## Min. : 0.000 Min. :0.00000 Min. :0.0000 ## 1st Qu.: 1.000 1st Qu.:0.00000 1st Qu.:0.0000 ## Median : 1.000 Median :0.00000 Median :0.0000 ## Mean : 1.479 Mean :0.05749 Mean :0.5127 ## 3rd Qu.: 2.000 3rd Qu.:0.00000 3rd Qu.:1.0000 ## Max. :12.000 Max. :4.00000 Max. :8.0000 ## ActiveSubscriptions ExpiredSubscriptions RequestedCancellations ## Min. :0.0000 Min. : 1.000 Min. :0.0000 ## 1st Qu.:0.0000 1st Qu.: 1.000 1st Qu.:0.0000 ## Median :0.0000 Median : 2.000 Median :0.0000 ## Mean :0.1299 Mean : 1.978 Mean :0.1002 ## 3rd Qu.:0.0000 3rd Qu.: 3.000 3rd Qu.:0.0000 ## Max. :5.0000 Max. :13.000 Max. :9.0000 ## NoPayCancellations PaidComplaints GiftDonor NumberGiftDonations ## Min. :0.0000 Min. :0.000000 Length:42077 Min. : 0.0000 ## 1st Qu.:0.0000 1st Qu.:0.000000 Class :character 1st Qu.: 0.0000 ## Median :0.0000 Median :0.000000 Mode :character Median :
0.0000 ## Mean :0.1749 Mean :0.007058 Mean : 0.2854 ## 3rd Qu.:0.0000 3rd Qu.:0.000000 3rd Qu.: 0.0000 ## Max. :8.0000 Max. :2.000000 Max. :94.0000 ## MonthsSince1stOrder MonthsSinceLastOrder MonthsSinceExpire Renewal ## Min. : 6.0 Min. : 4.00 Min. : 3.00 Length:42077 ## 1st Qu.: 59.0 1st Qu.: 48.00 1st Qu.: 23.00 Class :character ## Median : 100.0 Median : 72.00 Median : 46.00 Mode :character ## Mean : 120.9 Mean : 75.18 Mean : 49.46 ## 3rd Qu.: 155.0 3rd Qu.:103.00 3rd Qu.: 73.00 ## Max. :1338.0 Max. :224.00 Max. :120.00 ##Q1.1 exploring and modifying data #Converting character variables to factors fact_var <- c ( "DwellingType" , "Gender" , "Marital" , "ChildPresent" , "Occupation" , "MagazineStatus" , "LastPaymentType" , "GiftDonor" , "Renewal" ) greydata[fact_var] <- lapply (greydata[fact_var], factor) summary (greydata) ## CustomerID Age HomeOwner ResidenceLength DwellingType ## Min. : 1 Min. :18.00 Min. : 0.00 Min. : 1.000 M: 4582 ## 1st Qu.:10520 1st Qu.:42.00 1st Qu.:100.00 1st Qu.: 4.000 S:37486 ## Median :21039 Median :52.00 Median :100.00 Median : 9.000 U: 9 ## Mean :21039 Mean :51.64 Mean : 89.23 Mean : 8.525 ## 3rd Qu.:31558 3rd Qu.:62.00 3rd Qu.:100.00 3rd Qu.:14.000 ## Max. :42077 Max. :84.00 Max. :100.00 Max. :14.000 ## ## Gender Marital HouseholdSize ChildPresent Child0.5 ## F:35172 M:30747 Min. :1.00 N:12038 Min. : 0.00 ## M: 6460 S:11301 1st Qu.:2.00 U: 3807 1st Qu.: 15.00
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## U: 445 U: 29 Median :3.00 Y:26232 Median : 45.00 ## Mean :3.16 Mean : 43.49 ## 3rd Qu.:4.00 3rd Qu.: 65.00 ## Max. :6.00 Max. :100.00 ## ## Child6.12 Child13.18 Income Occupation HomeValue ## Min. : 0.00 Min. : 0.00 Min. : 5000 B: 3692 Min. :1.000 ## 1st Qu.: 0.00 1st Qu.: 25.00 1st Qu.: 42500 H: 2831 1st Qu.:3.000 ## Median : 35.00 Median : 45.00 Median : 78000 M: 9727 Median :4.000 ## Mean : 43.06 Mean : 50.58 Mean : 91223 R: 3340 Mean :4.365 ## 3rd Qu.:100.00 3rd Qu.:100.00 3rd Qu.:122000 U: 7852 3rd Qu.:6.000 ## Max. :100.00 Max. :100.00 Max. :500000 W:14635 Max. :9.000 ## ## MagazineStatus PaidDirectMailOrders YearsSinceLastOrder TotalAmountPaid ## A: 4792 Min. : 0.0000 Min. : 0.000 Min. : 0.00 ## B: 2674 1st Qu.: 0.0000 1st Qu.: 3.000 1st Qu.: 19.00 ## C: 1406 Median : 0.0000 Median : 5.000 Median : 40.00 ## E:17944 Mean : 0.8113 Mean : 5.332 Mean : 59.41 ## O:15145 3rd Qu.: 1.0000 3rd Qu.: 8.000 3rd Qu.: 80.91 ## S: 116 Max. :16.0000 Max. :15.000 Max. :1304.73 ## ## DollarsPerIssue TotalPaidOrders MonthsSinceLastPayment LastPaymentType ## Min. :0.0000 Min. : 0.000 Min. : 0.00 A :28727 ## 1st Qu.:0.5200 1st Qu.: 1.000 1st Qu.: 32.00 1 : 4922 ## Median :0.7100 Median : 2.000 Median : 57.00 0 : 1781 ## Mean :0.7511 Mean : 3.762 Mean : 60.44 2 : 1716 ## 3rd Qu.:0.9200 3rd Qu.: 5.000 3rd Qu.: 88.00 F : 1483 ## Max. :5.0000 Max. :109.000 Max. :312.00 S :
673 ## (Other): 2775 ## UnpaidMagazines PaidCashMagazines PaidReinstateMagazines PaidCreditMagazines ## Min. : 0.00 Min. : 0.000 Min. :0.00000 Min. :0.0000 ## 1st Qu.: 0.00 1st Qu.: 1.000 1st Qu.:0.00000 1st Qu.:0.0000 ## Median : 0.00 Median : 1.000 Median :0.00000 Median :0.0000 ## Mean : 0.21 Mean : 1.479 Mean :0.05749 Mean :0.5127 ## 3rd Qu.: 0.00 3rd Qu.: 2.000 3rd Qu.:0.00000 3rd Qu.:1.0000 ## Max. :10.00 Max. :12.000 Max. :4.00000 Max. :8.0000 ## ## ActiveSubscriptions ExpiredSubscriptions RequestedCancellations ## Min. :0.0000 Min. : 1.000 Min. :0.0000 ## 1st Qu.:0.0000 1st Qu.: 1.000 1st Qu.:0.0000 ## Median :0.0000 Median : 2.000 Median :0.0000 ## Mean :0.1299 Mean : 1.978 Mean :0.1002 ## 3rd Qu.:0.0000 3rd Qu.: 3.000 3rd Qu.:0.0000 ## Max. :5.0000 Max. :13.000 Max. :9.0000 ## ## NoPayCancellations PaidComplaints GiftDonor NumberGiftDonations ## Min. :0.0000 Min. :0.000000 N:37781 Min. : 0.0000 ## 1st Qu.:0.0000 1st Qu.:0.000000 Y: 4296 1st Qu.: 0.0000 ## Median :0.0000 Median :0.000000 Median : 0.0000 ## Mean :0.1749 Mean :0.007058 Mean : 0.2854 ## 3rd Qu.:0.0000 3rd Qu.:0.000000 3rd Qu.: 0.0000 ## Max. :8.0000 Max. :2.000000 Max. :94.0000 ## ## MonthsSince1stOrder MonthsSinceLastOrder MonthsSinceExpire Renewal ## Min. : 6.0 Min. : 4.00 Min. : 3.00 No :41183 ## 1st Qu.: 59.0 1st Qu.: 48.00 1st Qu.: 23.00 Yes: 894
## Median : 100.0 Median : 72.00 Median : 46.00 ## Mean : 120.9 Mean : 75.18 Mean : 49.46 ## 3rd Qu.: 155.0 3rd Qu.:103.00 3rd Qu.: 73.00 ## Max. :1338.0 Max. :224.00 Max. :120.00 ## colSums ( is.na (greydata)) ## CustomerID Age HomeOwner ## 0 0 0 ## ResidenceLength DwellingType Gender ## 0 0 0 ## Marital HouseholdSize ChildPresent ## 0 0 0 ## Child0.5 Child6.12 Child13.18 ## 0 0 0 ## Income Occupation HomeValue ## 0 0 0 ## MagazineStatus PaidDirectMailOrders YearsSinceLastOrder ## 0 0 0 ## TotalAmountPaid DollarsPerIssue TotalPaidOrders ## 0 0 0 ## MonthsSinceLastPayment LastPaymentType UnpaidMagazines ## 0 0 0 ## PaidCashMagazines PaidReinstateMagazines PaidCreditMagazines ## 0 0 0 ## ActiveSubscriptions ExpiredSubscriptions RequestedCancellations
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## 0 0 0 ## NoPayCancellations PaidComplaints GiftDonor ## 0 0 0 ## NumberGiftDonations MonthsSince1stOrder MonthsSinceLastOrder ## 0 0 0 ## MonthsSinceExpire Renewal ## 0 0 #variable with high corelation numdata <- greydata[ sapply (greydata, is.numeric)] corr_matrix <- cor (numdata) print (corr_matrix) ## CustomerID Age HomeOwner ResidenceLength ## CustomerID 1.000000000 -0.33184727 -0.253145556 - 0.174452403 ## Age -0.331847266 1.00000000 0.142860879 0.299291310 ## HomeOwner -0.253145556 0.14286088 1.000000000 0.280934998 ## ResidenceLength -0.174452403 0.29929131 0.280934998 1.000000000 ## HouseholdSize 0.028806675 -0.06795287 0.150733395 0.176035250 ## Child0.5 0.138650693 -0.30472457 0.027690312 - 0.035756252 ## Child6.12 0.145192992 -0.33967450 0.057148153 - 0.007592537 ## Child13.18 0.055244686 -0.12765800 0.115793603 0.128673733 ## Income -0.021477584 -0.03069579 0.207633236 0.109774867 ## HomeValue -0.022257242 -0.01099303 0.059091478 - 0.016730174 ## PaidDirectMailOrders -0.370053575 0.26456488 0.100484344 0.141772775 ## YearsSinceLastOrder -0.057324737 0.08456207 0.032798293 0.035289456 ## TotalAmountPaid -0.243727085 0.17420662 0.033960456 0.103972125 ## DollarsPerIssue 0.014621464 0.03271240 -0.024478715 0.010679179 ## TotalPaidOrders -0.303736273 0.21541529 0.078458311
0.135570684 ## MonthsSinceLastPayment -0.070759403 0.08601601 0.034882415 0.041855791 ## UnpaidMagazines -0.131020631 0.10495129 0.014739769 0.051729273 ## PaidCashMagazines 0.007089021 -0.01130039 -0.008171712 0.028799743 ## PaidReinstateMagazines -0.102893176 0.08866709 0.023312217 0.045917412 ## PaidCreditMagazines -0.246216582 0.11246187 0.075042495 0.060970364 ## ActiveSubscriptions -0.070547253 0.03354888 0.024733360 0.034960442 ## ExpiredSubscriptions -0.138197882 0.02618814 0.047487104 0.062306165 ## RequestedCancellations -0.123079880 0.10342953 0.034919347 0.072388366 ## NoPayCancellations 0.012875588 -0.05683241 -0.034690256 - 0.036311289 ## PaidComplaints -0.014338127 0.01979380 -0.008800245 0.004675741 ## NumberGiftDonations -0.102836157 0.07940075 0.030516253 0.041173141 ## MonthsSince1stOrder -0.337846242 0.26128775 0.126765416 0.189592219 ## MonthsSinceLastOrder -0.170914747 0.11350047 0.092077141 0.100638812 ## MonthsSinceExpire -0.096321354 0.08180228 0.085549745 0.088595649 ## HouseholdSize Child0.5 Child6.12 Child13.18 ## CustomerID 0.028806675 0.138650693 0.1451929920 0.0552446858 ## Age -0.067952873 -0.304724572 -0.3396745018 - 0.1276579970 ## HomeOwner 0.150733395 0.027690312 0.0571481535 0.1157936025 ## ResidenceLength 0.176035250 -0.035756252 -0.0075925371 0.1286737332 ## HouseholdSize 1.000000000 0.257190107 0.3102016111 0.3895974212 ## Child0.5 0.257190107 1.000000000 0.5004360917 0.2270845697 ## Child6.12 0.310201611 0.500436092 1.0000000000 0.4185440802 ## Child13.18 0.389597421 0.227084570 0.4185440802 1.0000000000 ## Income 0.247746309 0.117345480 0.1706923833 0.1883913327 ## HomeValue 0.061880885 -0.002429308 0.0540542023
0.0543149944 ## PaidDirectMailOrders 0.010616874 -0.081780568 -0.0702497573 - 0.0145537243 ## YearsSinceLastOrder -0.001125406 -0.119420588 -0.0397659260 0.0014256201 ## TotalAmountPaid 0.023815884 -0.041056222 -0.0286956850 0.0163333932 ## DollarsPerIssue -0.001391100 -0.059185309 -0.0300846527 0.0132268098 ## TotalPaidOrders 0.026347482 -0.047107492 -0.0390793343 0.0048755081 ## MonthsSinceLastPayment 0.004215917 -0.092767866 -0.0335793631 0.0045587124 ## UnpaidMagazines 0.020320320 -0.008358126 -0.0177757548 0.0009923008 ## PaidCashMagazines 0.042754793 0.084593565 0.0768557030 0.0486029445 ## PaidReinstateMagazines 0.017430056 -0.024192699 -0.0247494048 0.0063133670 ## PaidCreditMagazines 0.015013271 -0.022591626 0.0006091551 0.0120672293 ## ActiveSubscriptions 0.018555738 0.047920104 0.0261954580 0.0138351784 ## ExpiredSubscriptions 0.070326191 0.099384720 0.1310638430 0.0983954138 ## RequestedCancellations 0.022033276 -0.031369106 -0.0314745964 0.0006810198 ## NoPayCancellations 0.036582495 0.144432015 0.0891053913 0.0155014776 ## PaidComplaints 0.007682578 -0.003222106 -0.0006952938 0.0096160881 ## NumberGiftDonations -0.005189334 -0.032610738 -0.0247361040 - 0.0150460384 ## MonthsSince1stOrder 0.063717633 -0.085869341 -0.0517332831 0.0406157078 ## MonthsSinceLastOrder 0.050793217 -0.037083769 0.0290356121 0.0486954313 ## MonthsSinceExpire 0.049464752 -0.030493769 0.0333894425 0.0503755845 ## Income HomeValue PaidDirectMailOrders ## CustomerID -0.021477584 -0.022257242 - 0.37005357 ## Age -0.030695787 -0.010993027 0.26456488 ## HomeOwner 0.207633236 0.059091478 0.10048434 ## ResidenceLength 0.109774867 -0.016730174 0.14177277 ## HouseholdSize 0.247746309 0.061880885
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0.01061687 ## Child0.5 0.117345480 -0.002429308 - 0.08178057 ## Child6.12 0.170692383 0.054054202 - 0.07024976 ## Child13.18 0.188391333 0.054314994 - 0.01455372 ## Income 1.000000000 0.519899479 0.04267370 ## HomeValue 0.519899479 1.000000000 0.03339091 ## PaidDirectMailOrders 0.042673701 0.033390909 1.00000000 ## YearsSinceLastOrder 0.021148742 0.036936907 - 0.04679703 ## TotalAmountPaid 0.043519054 0.026238744 0.46516154 ## DollarsPerIssue 0.018023514 0.021140038 - 0.07556858 ## TotalPaidOrders 0.071452722 0.055865523 0.56867059 ## MonthsSinceLastPayment 0.025079086 0.041082648 - 0.03265605 ## UnpaidMagazines -0.027761490 -0.031681123 0.24300788 ## PaidCashMagazines 0.038717498 -0.007679461 0.07412758 ## PaidReinstateMagazines 0.004852932 -0.005420643 0.20409851 ## PaidCreditMagazines 0.049987956 0.042699463 0.50565811 ## ActiveSubscriptions 0.039900976 0.016191760 0.18849484 ## ExpiredSubscriptions 0.083936874 0.029869915 0.38437847 ## RequestedCancellations 0.002024003 -0.009404041 0.20300282 ## NoPayCancellations -0.025614404 -0.035441501 0.03755356 ## PaidComplaints -0.011699640 -0.016062636 0.02056556 ## NumberGiftDonations 0.033828005 0.037970368 0.17728953 ## MonthsSince1stOrder 0.099311814 0.078386834 0.40527016 ## MonthsSinceLastOrder 0.110736620 0.093011743 0.16845630 ## MonthsSinceExpire 0.111375108 0.091931279 0.03291118 ## YearsSinceLastOrder TotalAmountPaid
DollarsPerIssue ## CustomerID -0.057324737 -0.24372709 0.01462146 ## Age 0.084562072 0.17420662 0.03271240 ## HomeOwner 0.032798293 0.03396046 - 0.02447871 ## ResidenceLength 0.035289456 0.10397212 0.01067918 ## HouseholdSize -0.001125406 0.02381588 - 0.00139110 ## Child0.5 -0.119420588 -0.04105622 - 0.05918531 ## Child6.12 -0.039765926 -0.02869568 - 0.03008465 ## Child13.18 0.001425620 0.01633339 0.01322681 ## Income 0.021148742 0.04351905 0.01802351 ## HomeValue 0.036936907 0.02623874 0.02114004 ## PaidDirectMailOrders -0.046797028 0.46516154 - 0.07556858 ## YearsSinceLastOrder 1.000000000 -0.07454735 0.16331535 ## TotalAmountPaid -0.074547347 1.00000000 0.34335802 ## DollarsPerIssue 0.163315354 0.34335802 1.00000000 ## TotalPaidOrders -0.121126367 0.80316977 0.11417511 ## MonthsSinceLastPayment 0.802019327 -0.06938571 0.12550388 ## UnpaidMagazines -0.088958691 0.16085349 - 0.13659997 ## PaidCashMagazines -0.304212500 0.44943108 0.16538992 ## PaidReinstateMagazines 0.006628856 0.21468259 0.01806404 ## PaidCreditMagazines 0.019377361 0.25345594 - 0.05144049 ## ActiveSubscriptions -0.383731599 0.28341709 0.02153229 ## ExpiredSubscriptions -0.172964061 0.52463435 0.07911823 ## RequestedCancellations -0.026789151 0.14970367 - 0.05848516 ## NoPayCancellations -0.130452261 0.08318335 - 0.08981382 ## PaidComplaints -0.002817095 0.06075209
0.01085790 ## NumberGiftDonations -0.028654297 0.25177136 0.01450155 ## MonthsSince1stOrder 0.212289817 0.41853369 0.06852579 ## MonthsSinceLastOrder 0.516050131 0.19483205 0.19952437 ## MonthsSinceExpire 0.492935011 0.06633764 0.17184874 ## TotalPaidOrders MonthsSinceLastPayment UnpaidMagazines ## CustomerID -0.303736273 -0.070759403 - 0.1310206305 ## Age 0.215415289 0.086016011 0.1049512906 ## HomeOwner 0.078458311 0.034882415 0.0147397686 ## ResidenceLength 0.135570684 0.041855791 0.0517292733 ## HouseholdSize 0.026347482 0.004215917 0.0203203198 ## Child0.5 -0.047107492 -0.092767866 - 0.0083581255 ## Child6.12 -0.039079334 -0.033579363 - 0.0177757548 ## Child13.18 0.004875508 0.004558712 0.0009923008 ## Income 0.071452722 0.025079086 - 0.0277614901 ## HomeValue 0.055865523 0.041082648 - 0.0316811232 ## PaidDirectMailOrders 0.568670590 -0.032656047 0.2430078803 ## YearsSinceLastOrder -0.121126367 0.802019327 - 0.0889586911 ## TotalAmountPaid 0.803169774 -0.069385706 0.1608534908 ## DollarsPerIssue 0.114175113 0.125503880 - 0.1365999711 ## TotalPaidOrders 1.000000000 -0.124432154 0.2032664388 ## MonthsSinceLastPayment -0.124432154 1.000000000 - 0.0274413182 ## UnpaidMagazines 0.203266439 -0.027441318 1.0000000000 ## PaidCashMagazines 0.429429869 -0.355597336 0.0183616623 ## PaidReinstateMagazines 0.216457262 0.030804508 0.0863465734 ## PaidCreditMagazines 0.287891863 0.040434723
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0.1169881057 ## ActiveSubscriptions 0.296727064 -0.405548969 0.0454311197 ## ExpiredSubscriptions 0.540906500 -0.186656960 0.1185745913 ## RequestedCancellations 0.189368483 0.008052190 0.6938895193 ## NoPayCancellations 0.078034745 -0.065346222 0.5371785562 ## PaidComplaints 0.037268225 0.002264669 0.0381981070 ## NumberGiftDonations 0.467464741 -0.034190051 0.0576299965 ## MonthsSince1stOrder 0.524653629 0.276031741 0.1904710688 ## MonthsSinceLastOrder 0.138838982 0.639543254 0.0343095514 ## MonthsSinceExpire 0.058262987 0.606652741 0.0087976498 ## PaidCashMagazines PaidReinstateMagazines ## CustomerID 0.007089021 -0.102893176 ## Age -0.011300394 0.088667092 ## HomeOwner -0.008171712 0.023312217 ## ResidenceLength 0.028799743 0.045917412 ## HouseholdSize 0.042754793 0.017430056 ## Child0.5 0.084593565 -0.024192699 ## Child6.12 0.076855703 -0.024749405 ## Child13.18 0.048602944 0.006313367 ## Income 0.038717498 0.004852932 ## HomeValue -0.007679461 -0.005420643 ## PaidDirectMailOrders 0.074127577 0.204098510 ## YearsSinceLastOrder -0.304212500 0.006628856 ## TotalAmountPaid 0.449431075 0.214682590 ## DollarsPerIssue 0.165389925 0.018064037 ## TotalPaidOrders 0.429429869 0.216457262 ## MonthsSinceLastPayment -0.355597336 0.030804508 ## UnpaidMagazines 0.018361662 0.086346573 ## PaidCashMagazines 1.000000000 0.022220396 ## PaidReinstateMagazines 0.022220396 1.000000000 ## PaidCreditMagazines -0.266696683 0.074427994 ## ActiveSubscriptions 0.313042133 0.025665933 ## ExpiredSubscriptions 0.663567999 0.265031951 ## RequestedCancellations 0.041420583 0.078110196 ## NoPayCancellations 0.131819248 0.047551219 ## PaidComplaints 0.078276522 0.023763813 ## NumberGiftDonations 0.075252232 0.041036131 ## MonthsSince1stOrder 0.037350544 0.156120114 ## MonthsSinceLastOrder -0.096350331 0.079785269 ## MonthsSinceExpire -0.077266534 0.061292559 ## PaidCreditMagazines ActiveSubscriptions
## CustomerID -0.2462165819 -0.070547253 ## Age 0.1124618676 0.033548877 ## HomeOwner 0.0750424953 0.024733360 ## ResidenceLength 0.0609703643 0.034960442 ## HouseholdSize 0.0150132714 0.018555738 ## Child0.5 -0.0225916264 0.047920104 ## Child6.12 0.0006091551 0.026195458 ## Child13.18 0.0120672293 0.013835178 ## Income 0.0499879563 0.039900976 ## HomeValue 0.0426994625 0.016191760 ## PaidDirectMailOrders 0.5056581125 0.188494839 ## YearsSinceLastOrder 0.0193773615 -0.383731599 ## TotalAmountPaid 0.2534559364 0.283417087 ## DollarsPerIssue -0.0514404866 0.021532290 ## TotalPaidOrders 0.2878918631 0.296727064 ## MonthsSinceLastPayment 0.0404347234 -0.405548969 ## UnpaidMagazines 0.1169881057 0.045431120 ## PaidCashMagazines -0.2666966826 0.313042133 ## PaidReinstateMagazines 0.0744279940 0.025665933 ## PaidCreditMagazines 1.0000000000 0.089230774 ## ActiveSubscriptions 0.0892307741 1.000000000 ## ExpiredSubscriptions 0.3688690325 0.063966906 ## RequestedCancellations 0.1058490832 0.033085322 ## NoPayCancellations 0.0365556967 0.024005042 ## PaidComplaints 0.0209867235 -0.001860688 ## NumberGiftDonations 0.0944037478 0.099067648 ## MonthsSince1stOrder 0.2227152121 0.019560148 ## MonthsSinceLastOrder 0.2304269268 -0.046258478 ## MonthsSinceExpire 0.1381834719 -0.058883824 ## ExpiredSubscriptions RequestedCancellations ## CustomerID -0.13819788 -0.1230798800 ## Age 0.02618814 0.1034295256 ## HomeOwner 0.04748710 0.0349193468 ## ResidenceLength 0.06230617 0.0723883661 ## HouseholdSize 0.07032619 0.0220332762 ## Child0.5 0.09938472 -0.0313691059 ## Child6.12 0.13106384 -0.0314745964 ## Child13.18 0.09839541 0.0006810198 ## Income 0.08393687 0.0020240030 ## HomeValue 0.02986992 -0.0094040411 ## PaidDirectMailOrders 0.38437847 0.2030028205 ## YearsSinceLastOrder -0.17296406 -0.0267891512 ## TotalAmountPaid 0.52463435 0.1497036686 ## DollarsPerIssue 0.07911823 -0.0584851624 ## TotalPaidOrders 0.54090650 0.1893684834 ## MonthsSinceLastPayment -0.18665696 0.0080521895 ## UnpaidMagazines 0.11857459 0.6938895193 ## PaidCashMagazines 0.66356800 0.0414205832 ## PaidReinstateMagazines 0.26503195 0.0781101963 ## PaidCreditMagazines 0.36886903 0.1058490832
## ActiveSubscriptions 0.06396691 0.0330853219 ## ExpiredSubscriptions 1.00000000 0.0878935283 ## RequestedCancellations 0.08789353 1.0000000000 ## NoPayCancellations 0.06326952 0.0666686314 ## PaidComplaints 0.02494383 0.0313876003 ## NumberGiftDonations 0.10744018 0.0692829695 ## MonthsSince1stOrder 0.19692276 0.1994982691 ## MonthsSinceLastOrder 0.08819792 0.0596394475 ## MonthsSinceExpire 0.05195587 0.0390748950 ## NoPayCancellations PaidComplaints NumberGiftDonations ## CustomerID 0.012875588 -0.0143381268 - 0.102836157 ## Age -0.056832412 0.0197937976 0.079400745 ## HomeOwner -0.034690256 -0.0088002450 0.030516253 ## ResidenceLength -0.036311289 0.0046757412 0.041173141 ## HouseholdSize 0.036582495 0.0076825783 - 0.005189334 ## Child0.5 0.144432015 -0.0032221057 - 0.032610738 ## Child6.12 0.089105391 -0.0006952938 - 0.024736104 ## Child13.18 0.015501478 0.0096160881 - 0.015046038 ## Income -0.025614404 -0.0116996398 0.033828005 ## HomeValue -0.035441501 -0.0160626363 0.037970368 ## PaidDirectMailOrders 0.037553557 0.0205655551 0.177289533 ## YearsSinceLastOrder -0.130452261 -0.0028170951 - 0.028654297 ## TotalAmountPaid 0.083183347 0.0607520866 0.251771355 ## DollarsPerIssue -0.089813817 0.0108579028 0.014501550 ## TotalPaidOrders 0.078034745 0.0372682250 0.467464741 ## MonthsSinceLastPayment -0.065346222 0.0022646686 - 0.034190051 ## UnpaidMagazines 0.537178556 0.0381981070 0.057629996 ## PaidCashMagazines 0.131819248 0.0782765218 0.075252232 ## PaidReinstateMagazines 0.047551219 0.0237638133 0.041036131 ## PaidCreditMagazines 0.036555697 0.0209867235
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0.094403748 ## ActiveSubscriptions 0.024005042 -0.0018606876 0.099067648 ## ExpiredSubscriptions 0.063269515 0.0249438317 0.107440183 ## RequestedCancellations 0.066668631 0.0313876003 0.069282969 ## NoPayCancellations 1.000000000 0.0200078224 0.005201898 ## PaidComplaints 0.020007822 1.0000000000 0.010514209 ## NumberGiftDonations 0.005201898 0.0105142085 1.000000000 ## MonthsSince1stOrder 0.047294656 0.0469976908 0.182005485 ## MonthsSinceLastOrder 0.002155366 0.0162445397 0.036211801 ## MonthsSinceExpire -0.008135343 0.0117801411 0.016444106 ## MonthsSince1stOrder MonthsSinceLastOrder ## CustomerID -0.33784624 -0.170914747 ## Age 0.26128775 0.113500473 ## HomeOwner 0.12676542 0.092077141 ## ResidenceLength 0.18959222 0.100638812 ## HouseholdSize 0.06371763 0.050793217 ## Child0.5 -0.08586934 -0.037083769 ## Child6.12 -0.05173328 0.029035612 ## Child13.18 0.04061571 0.048695431 ## Income 0.09931181 0.110736620 ## HomeValue 0.07838683 0.093011743 ## PaidDirectMailOrders 0.40527016 0.168456302 ## YearsSinceLastOrder 0.21228982 0.516050131 ## TotalAmountPaid 0.41853369 0.194832047 ## DollarsPerIssue 0.06852579 0.199524367 ## TotalPaidOrders 0.52465363 0.138838982 ## MonthsSinceLastPayment 0.27603174 0.639543254 ## UnpaidMagazines 0.19047107 0.034309551 ## PaidCashMagazines 0.03735054 -0.096350331 ## PaidReinstateMagazines 0.15612011 0.079785269 ## PaidCreditMagazines 0.22271521 0.230426927 ## ActiveSubscriptions 0.01956015 -0.046258478 ## ExpiredSubscriptions 0.19692276 0.088197915 ## RequestedCancellations 0.19949827 0.059639447 ## NoPayCancellations 0.04729466 0.002155366 ## PaidComplaints 0.04699769 0.016244540 ## NumberGiftDonations 0.18200548 0.036211801 ## MonthsSince1stOrder 1.00000000 0.431466834 ## MonthsSinceLastOrder 0.43146683 1.000000000 ## MonthsSinceExpire 0.35847313 0.921104469 ## MonthsSinceExpire
## CustomerID -0.096321354 ## Age 0.081802277 ## HomeOwner 0.085549745 ## ResidenceLength 0.088595649 ## HouseholdSize 0.049464752 ## Child0.5 -0.030493769 ## Child6.12 0.033389443 ## Child13.18 0.050375585 ## Income 0.111375108 ## HomeValue 0.091931279 ## PaidDirectMailOrders 0.032911183 ## YearsSinceLastOrder 0.492935011 ## TotalAmountPaid 0.066337644 ## DollarsPerIssue 0.171848735 ## TotalPaidOrders 0.058262987 ## MonthsSinceLastPayment 0.606652741 ## UnpaidMagazines 0.008797650 ## PaidCashMagazines -0.077266534 ## PaidReinstateMagazines 0.061292559 ## PaidCreditMagazines 0.138183472 ## ActiveSubscriptions -0.058883824 ## ExpiredSubscriptions 0.051955873 ## RequestedCancellations 0.039074895 ## NoPayCancellations -0.008135343 ## PaidComplaints 0.011780141 ## NumberGiftDonations 0.016444106 ## MonthsSince1stOrder 0.358473131 ## MonthsSinceLastOrder 0.921104469 ## MonthsSinceExpire 1.000000000 #finding and removing variables with high coreltion high_cor <- findCorrelation (corr_matrix, cutoff = 0.75 ) greydata <- greydata %>% select ( - CustomerID,) greydata <- greydata %>% select ( - c ( "ExpiredSubscriptions" , "PaidDirectMailOrders" )) #Q1.2 split the data into training and testing sets (70% for training set) set.seed ( 123 ) train_indices <- sample ( nrow (greydata), 0.7 * nrow (greydata)) train <- greydata[train_indices, ] test <- greydata[ - train_indices, ] # Convert 'Renewal' to a factor train $ Renewal <- as.factor (train $ Renewal) # random forest model set.seed ( 123 ) rand_model <- randomForest (Renewal ~ ., data = train, ntree = 100 )
# Predictions on test set pred <- predict (rand_model, newdata = test) # Converting Renewal in the test set to a factor test $ Renewal <- as.factor (test $ Renewal) # Convert predictions to a factor with the same levels as test$Renewal pred <- factor (pred, levels = levels (test $ Renewal)) # confusion matrix confusionMatrix (pred, test $ Renewal) ## Confusion Matrix and Statistics ## ## Reference ## Prediction No Yes ## No 12333 159 ## Yes 22 110 ## ## Accuracy : 0.9857 ## 95% CI : (0.9834, 0.9877) ## No Information Rate : 0.9787 ## P-Value [Acc > NIR] : 5.45e-09 ## ## Kappa : 0.5422 ## ## Mcnemar's Test P-Value : < 2.2e-16 ## ## Sensitivity : 0.9982 ## Specificity : 0.4089 ## Pos Pred Value : 0.9873 ## Neg Pred Value : 0.8333 ## Prevalence : 0.9787 ## Detection Rate : 0.9769 ## Detection Prevalence : 0.9895 ## Balanced Accuracy : 0.7036 ## ## 'Positive' Class : No ## # logistic regression model log_model <- glm (Renewal ~ ., data = train, family = binomial) ## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred summary (log_model) ## ## Call: ## glm(formula = Renewal ~ ., family = binomial, data = train)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## ## Coefficients: ## Estimate Std. Error z value Pr(>|z|) ## (Intercept) -8.185e+00 6.210e-01 -13.180 < 2e-16 *** ## Age -7.303e-04 4.400e-03 -0.166 0.868163 ## HomeOwner 4.983e-03 2.112e-03 2.359 0.018327 * ## ResidenceLength -3.105e-03 9.840e-03 -0.316 0.752325 ## DwellingTypeS -1.386e-01 1.689e-01 -0.821 0.411914 ## DwellingTypeU -1.113e+01 1.600e+03 -0.007 0.994451 ## GenderM 2.366e-01 1.142e-01 2.073 0.038186 * ## GenderU 2.707e-01 5.389e-01 0.502 0.615427 ## MaritalS -1.179e-01 1.306e-01 -0.903 0.366526 ## MaritalU -1.292e+01 6.913e+02 -0.019 0.985089 ## HouseholdSize 6.271e-02 3.389e-02 1.850 0.064258 . ## ChildPresentU -1.381e-01 2.601e-01 -0.531 0.595473 ## ChildPresentY -3.327e-01 1.473e-01 -2.259 0.023911 * ## Child0.5 7.318e-04 1.403e-03 0.521 0.602070 ## Child6.12 1.766e-02 1.523e-03 11.599 < 2e-16 *** ## Child13.18 6.585e-03 1.561e-03 4.218 2.46e-05 *** ## Income 3.630e-06 5.684e-07 6.387 1.70e-10 *** ## OccupationH 1.109e-01 2.151e-01 0.516 0.606194 ## OccupationM 1.708e-01 1.747e-01 0.977 0.328395 ## OccupationR 3.968e-01 2.172e-01 1.827 0.067761 . ## OccupationU 4.650e-02 1.929e-01 0.241 0.809491 ## OccupationW 3.242e-02 1.677e-01 0.193 0.846691 ## HomeValue 8.614e-03 2.216e-02 0.389 0.697472 ## MagazineStatusB 1.224e-01 3.932e-01 0.311 0.755486 ## MagazineStatusC -6.764e-01 4.687e-01 -1.443 0.148970 ## MagazineStatusE -1.043e-02 3.137e-01 -0.033 0.973489 ## MagazineStatusO -7.738e-02 3.440e-01 -0.225 0.822058 ## MagazineStatusS -6.936e-02 8.265e-01 -0.084 0.933127 ## YearsSinceLastOrder -3.937e-02 2.435e-02 -1.617 0.105953 ## TotalAmountPaid 3.817e-04 9.745e-04 0.392 0.695285 ## DollarsPerIssue 1.900e+00 9.476e-02 20.046 < 2e-16 *** ## TotalPaidOrders -1.548e-02 1.700e-02 -0.911 0.362391 ## MonthsSinceLastPayment 5.627e-03 2.746e-03 2.049 0.040473 * ## LastPaymentType1 6.584e-02 3.651e-01 0.180 0.856897 ## LastPaymentType2 2.498e-01 4.219e-01 0.592 0.553829 ## LastPaymentType3 1.823e-01 5.109e-01 0.357 0.721231 ## LastPaymentType4 1.399e-01 6.751e-01 0.207 0.835826 ## LastPaymentType5 1.146e+00 5.725e-01 2.001 0.045347 * ## LastPaymentType6 1.154e+00 6.849e-01 1.685 0.091994 . ## LastPaymentType7 -1.302e+01 4.427e+02 -0.029 0.976531 ## LastPaymentType8 -1.287e+01 5.863e+02 -0.022 0.982483 ## LastPaymentType9 -1.306e+01 9.640e+02 -0.014 0.989191 ## LastPaymentTypeA 4.158e-01 3.268e-01 1.272 0.203287 ## LastPaymentTypeE 1.382e+00 8.765e-01 1.577 0.114789 ## LastPaymentTypeF 3.721e-02 4.681e-01 0.080 0.936629 ## LastPaymentTypeG -1.323e+01 5.467e+02 -0.024 0.980694 ## LastPaymentTypeI 4.223e-01 6.889e-01 0.613 0.539843
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## LastPaymentTypeK 1.542e+00 7.099e-01 2.172 0.029871 * ## LastPaymentTypeL 1.028e+00 4.622e-01 2.223 0.026198 * ## LastPaymentTypeM -3.471e-01 7.851e-01 -0.442 0.658401 ## LastPaymentTypeS 1.386e+00 4.152e-01 3.337 0.000847 *** ## LastPaymentTypeU -1.107e+01 1.047e+03 -0.011 0.991566 ## UnpaidMagazines 4.113e-01 1.486e-01 2.767 0.005652 ** ## PaidCashMagazines 3.877e-02 4.950e-02 0.783 0.433415 ## PaidReinstateMagazines 9.617e-03 1.606e-01 0.060 0.952256 ## PaidCreditMagazines -2.119e-02 7.326e-02 -0.289 0.772417 ## ActiveSubscriptions 1.359e-01 2.433e-01 0.559 0.576447 ## RequestedCancellations -3.199e-01 1.765e-01 -1.813 0.069887 . ## NoPayCancellations -3.473e-01 1.475e-01 -2.354 0.018556 * ## PaidComplaints 1.720e-01 3.899e-01 0.441 0.659203 ## GiftDonorY 9.697e-02 1.499e-01 0.647 0.517655 ## NumberGiftDonations 7.183e-03 2.410e-02 0.298 0.765669 ## MonthsSince1stOrder 8.200e-03 5.260e-04 15.589 < 2e-16 *** ## MonthsSinceLastOrder -1.575e-02 3.786e-03 -4.161 3.17e-05 *** ## MonthsSinceExpire -3.692e-03 3.998e-03 -0.924 0.355691 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## (Dispersion parameter for binomial family taken to be 1) ## ## Null deviance: 6052.6 on 29452 degrees of freedom ## Residual deviance: 4761.3 on 29388 degrees of freedom ## AIC: 4891.3 ## ## Number of Fisher Scoring iterations: 16 # converting renewal to 0 & 1 train $ Renewal <- ifelse (train $ Renewal == "Yes" , 1 , 0 ) # training a logistic regression model log_model <- glm (Renewal ~ ., data = train, family = binomial) ## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred summary (log_model) ## ## Call: ## glm(formula = Renewal ~ ., family = binomial, data = train) ## ## Coefficients: ## Estimate Std. Error z value Pr(>|z|) ## (Intercept) -8.185e+00 6.210e-01 -13.180 < 2e-16 *** ## Age -7.303e-04 4.400e-03 -0.166 0.868163 ## HomeOwner 4.983e-03 2.112e-03 2.359 0.018327 * ## ResidenceLength -3.105e-03 9.840e-03 -0.316 0.752325 ## DwellingTypeS -1.386e-01 1.689e-01 -0.821 0.411914
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## DwellingTypeU -1.113e+01 1.600e+03 -0.007 0.994451 ## GenderM 2.366e-01 1.142e-01 2.073 0.038186 * ## GenderU 2.707e-01 5.389e-01 0.502 0.615427 ## MaritalS -1.179e-01 1.306e-01 -0.903 0.366526 ## MaritalU -1.292e+01 6.913e+02 -0.019 0.985089 ## HouseholdSize 6.271e-02 3.389e-02 1.850 0.064258 . ## ChildPresentU -1.381e-01 2.601e-01 -0.531 0.595473 ## ChildPresentY -3.327e-01 1.473e-01 -2.259 0.023911 * ## Child0.5 7.318e-04 1.403e-03 0.521 0.602070 ## Child6.12 1.766e-02 1.523e-03 11.599 < 2e-16 *** ## Child13.18 6.585e-03 1.561e-03 4.218 2.46e-05 *** ## Income 3.630e-06 5.684e-07 6.387 1.70e-10 *** ## OccupationH 1.109e-01 2.151e-01 0.516 0.606194 ## OccupationM 1.708e-01 1.747e-01 0.977 0.328395 ## OccupationR 3.968e-01 2.172e-01 1.827 0.067761 . ## OccupationU 4.650e-02 1.929e-01 0.241 0.809491 ## OccupationW 3.242e-02 1.677e-01 0.193 0.846691 ## HomeValue 8.614e-03 2.216e-02 0.389 0.697472 ## MagazineStatusB 1.224e-01 3.932e-01 0.311 0.755486 ## MagazineStatusC -6.764e-01 4.687e-01 -1.443 0.148970 ## MagazineStatusE -1.043e-02 3.137e-01 -0.033 0.973489 ## MagazineStatusO -7.738e-02 3.440e-01 -0.225 0.822058 ## MagazineStatusS -6.936e-02 8.265e-01 -0.084 0.933127 ## YearsSinceLastOrder -3.937e-02 2.435e-02 -1.617 0.105953 ## TotalAmountPaid 3.817e-04 9.745e-04 0.392 0.695285 ## DollarsPerIssue 1.900e+00 9.476e-02 20.046 < 2e-16 *** ## TotalPaidOrders -1.548e-02 1.700e-02 -0.911 0.362391 ## MonthsSinceLastPayment 5.627e-03 2.746e-03 2.049 0.040473 * ## LastPaymentType1 6.584e-02 3.651e-01 0.180 0.856897 ## LastPaymentType2 2.498e-01 4.219e-01 0.592 0.553829 ## LastPaymentType3 1.823e-01 5.109e-01 0.357 0.721231 ## LastPaymentType4 1.399e-01 6.751e-01 0.207 0.835826 ## LastPaymentType5 1.146e+00 5.725e-01 2.001 0.045347 * ## LastPaymentType6 1.154e+00 6.849e-01 1.685 0.091994 . ## LastPaymentType7 -1.302e+01 4.427e+02 -0.029 0.976531 ## LastPaymentType8 -1.287e+01 5.863e+02 -0.022 0.982483 ## LastPaymentType9 -1.306e+01 9.640e+02 -0.014 0.989191 ## LastPaymentTypeA 4.158e-01 3.268e-01 1.272 0.203287 ## LastPaymentTypeE 1.382e+00 8.765e-01 1.577 0.114789 ## LastPaymentTypeF 3.721e-02 4.681e-01 0.080 0.936629 ## LastPaymentTypeG -1.323e+01 5.467e+02 -0.024 0.980694 ## LastPaymentTypeI 4.223e-01 6.889e-01 0.613 0.539843 ## LastPaymentTypeK 1.542e+00 7.099e-01 2.172 0.029871 * ## LastPaymentTypeL 1.028e+00 4.622e-01 2.223 0.026198 * ## LastPaymentTypeM -3.471e-01 7.851e-01 -0.442 0.658401 ## LastPaymentTypeS 1.386e+00 4.152e-01 3.337 0.000847 *** ## LastPaymentTypeU -1.107e+01 1.047e+03 -0.011 0.991566 ## UnpaidMagazines 4.113e-01 1.486e-01 2.767 0.005652 ** ## PaidCashMagazines 3.877e-02 4.950e-02 0.783 0.433415 ## PaidReinstateMagazines 9.617e-03 1.606e-01 0.060 0.952256
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## PaidCreditMagazines -2.119e-02 7.326e-02 -0.289 0.772417 ## ActiveSubscriptions 1.359e-01 2.433e-01 0.559 0.576447 ## RequestedCancellations -3.199e-01 1.765e-01 -1.813 0.069887 . ## NoPayCancellations -3.473e-01 1.475e-01 -2.354 0.018556 * ## PaidComplaints 1.720e-01 3.899e-01 0.441 0.659203 ## GiftDonorY 9.697e-02 1.499e-01 0.647 0.517655 ## NumberGiftDonations 7.183e-03 2.410e-02 0.298 0.765669 ## MonthsSince1stOrder 8.200e-03 5.260e-04 15.589 < 2e-16 *** ## MonthsSinceLastOrder -1.575e-02 3.786e-03 -4.161 3.17e-05 *** ## MonthsSinceExpire -3.692e-03 3.998e-03 -0.924 0.355691 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## (Dispersion parameter for binomial family taken to be 1) ## ## Null deviance: 6052.6 on 29452 degrees of freedom ## Residual deviance: 4761.3 on 29388 degrees of freedom ## AIC: 4891.3 ## ## Number of Fisher Scoring iterations: 16 # Prediction on the test dataset pred <- predict (log_model, newdata = test, type = "response" ) # Converting probabilities to class labels (0 or 1) predicted_classes <- ifelse (pred > 0.5 , 1 , 0 ) # Confusion matrix conf_matrix <- table ( Actual = test $ Renewal, Predicted = predicted_classes) print ( "Confusion Matrix:" ) ## [1] "Confusion Matrix:" print (conf_matrix) ## Predicted ## Actual 0 1 ## No 12344 11 ## Yes 262 7 # evaluating accuracy accuracy <- sum ( diag (conf_matrix)) / sum (conf_matrix) print ( paste ( "Accuracy:" , accuracy)) ## [1] "Accuracy: 0.978374524714829" # Calculate precision precision <- conf_matrix[ 2 , 2 ] / sum (conf_matrix[, 2 ]) print ( paste ( "Precision:" , precision)) ## [1] "Precision: 0.388888888888889"
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
#Q1.3 ROC curve and AUC-ROC roc_curve <- roc (test $ Renewal, pred) ## Setting levels: control = No, case = Yes ## Setting direction: controls < cases print ( "ROC Curve:" ) ## [1] "ROC Curve:" print (roc_curve) ## ## Call: ## roc.default(response = test$Renewal, predictor = pred) ## ## Data: pred in 12355 controls (test$Renewal No) < 269 cases (test$Renewal Yes). ## Area under the curve: 0.8317 print ( paste ( "AUC-ROC:" , auc (roc_curve))) ## [1] "AUC-ROC: 0.83166756682348" ##model has approx 97% accuaracy and roc curve is approx .83 which indicates that predicted renewal rate is 97% of the test set and AUC suggests that the model has a good ability to discriminate between positive and negative outcomes. library (binom) ## Warning: package 'binom' was built under R version 4.3.2 file_path <- "C:/Users/Rishabh Arora/Downloads/professional.xlsx" professional <- readxl :: read_excel (file_path) ## New names: ## • `` -> `...9` ## • `` -> `...10` #Q2.1 descriptive stats summary (professional) ## Age Gender Real Estate Purchases? ## Min. :19.00 Length:410 Length:410 ## 1st Qu.:28.00 Class :character Class :character ## Median :30.00 Mode :character Mode :character ## Mean :30.11 ## 3rd Qu.:33.00 ## Max. :42.00 ## Value of Investments ($) Number of Transactions Broadband Access? ## Min. : 0 Min. : 0.000 Length:410
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## 1st Qu.: 18300 1st Qu.: 4.000 Class :character ## Median : 24800 Median : 6.000 Mode :character ## Mean : 28538 Mean : 5.973 ## 3rd Qu.: 34275 3rd Qu.: 7.000 ## Max. :133400 Max. :21.000 ## Household Income ($) Have Children? ...9 ...10 ## Min. : 16200 Length:410 Mode:logical Length:410 ## 1st Qu.: 51625 Class :character NA's:410 Class :character ## Median : 66050 Mode :character Mode :character ## Mean : 74460 ## 3rd Qu.: 88775 ## Max. :322500 #Q2.2 95% confidence interval for mean age of subscribers ageci95 <- t.test (professional $ Age) $ conf.int ##95% confidence interval for mean household income of subscribers incomeci95 <- t.test (professional $ ` Household Income ($) ` ) $ conf.int cat ( "95% Confidence Interval for Mean Age of Subscribers:" , ageci95, " \n " ) ## 95% Confidence Interval for Mean Age of Subscribers: 29.72153 30.50286 cat ( "95% Confidence Interval for Mean Income of Subscribers:" , incomeci95, " \n " ) ## 95% Confidence Interval for Mean Income of Subscribers: 71079.26 77839.77 #count of subscriber having broadband count_broadband <- table (professional $ ` Broadband Access? ` ) print (count_broadband) ## ## No Yes ## 154 256 #count of subscriber having children count_children <- table (professional $ ` Have Children? ` ) print (count_children)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
## ## No Yes ## 191 219 professional $ ` Broadband Access? ` <- as.factor (professional $ ` Broadband Access? ` ) professional $ ` Have Children? ` <- as.factor (professional $ ` Have Children? ` ) # Calculate proportions prop_broadband <- sum (professional $ ` Broadband Access? ` == "Yes" ) / nrow (professional) prop_children <- sum (professional $ ` Have Children? ` == "Yes" ) / nrow (professional) #Q2.3 Calculate 95% confidence intervals broadbandci95 <- binom.confint ( sum (professional $ ` Broadband Access? ` == "Yes" ), nrow (professional), conf.level = 0.95 , methods = "wilson" ) childrenci95 <- binom.confint ( sum (professional $ ` Have Children? ` == "Yes" ), nrow (professional), conf.level = 0.95 , methods = "wilson" ) print ( paste ( "95% CI for broadband: [" , broadbandci95 $ lower, "," , broadbandci95 $ upper, "]" )) ## [1] "95% CI for broadband: [ 0.576563157172795 , 0.6699080404947 ]" print ( paste ( "95% CI for children: [" , childrenci95 $ lower, "," , childrenci95 $ upper, "]" )) ## [1] "95% CI for children: [ 0.485768090246438 , 0.581890669897581 ]" #Q2.4 Would Young Professional be a good advertising outlet for online brokers? broadband_realest <- professional[professional $ ` Broadband Access? ` == "Yes" & professional $ ` Real Estate Purchases? ` == "Yes" , ] # Count the number of such subscribers count <- nrow (broadband_realest) print ( paste ( "Number of subscribers who have broadband access and are planning a real estate purchase:" , count)) ## [1] "Number of subscribers who have broadband access and are planning a real estate purchase: 115" ## from the above result we can see only 115 subscribers out of 410 have access to internet and planning a real estate which is around 28%, i.e very small, hence this magazine will not be be a good advertising outlet for online brokers. #Q2.5 Would this magazine be a good place to advertise for companies
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
selling educational software and computer games for young children? print (count_children) ## ## No Yes ## 191 219 ## result shows that around 53% of subscribers have children, hence this magazine be a good place to advertise for companies selling educational software and computer games for young children ## Telecom companies can also publish articles as 38% subscribers still don't have broadband at their homes which is a necessity in today's world. ##Q2.6 Descriptive statistics show that average age of subscribers is 30 and they are investing 38% of their total income on an average which is a very good number, So I believe advertisements and articles from investment brokers and mutual fund companies providing financial literacy would excite the subscribers most.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help