Dataset Customer_data.csv

This dataset was grabbed from:

https://www.kaggle.com/datasets/sanyamgoyal401/customer-purchases-behaviour-dataset/data

  id age gender income  education region loyalty_status purchase_frequency
1  1  27   Male  40682   Bachelor   East           Gold           frequent
2  2  29   Male  15317    Masters   West        Regular               rare
3  3  37   Male  38849   Bachelor   West         Silver               rare
4  4  30   Male  11568 HighSchool  South        Regular           frequent
5  5  31 Female  46952    College  North        Regular         occasional
6  6  38   Male   7347   Bachelor  South         Silver         occasional
  purchase_amount product_category promotion_usage satisfaction_score
1           18249            Books               0                  6
2            4557         Clothing               1                  6
3           11822         Clothing               0                  6
4            4098             Food               0                  7
5           19685         Clothing               1                  5
6            2822      Electronics               0                  5

Model Summary


Call:
lm(formula = purchase_amount ~ satisfaction_score + age + income + 
    education_numeric + region_numeric + loyalty_numeric + purchase_frequency_numeric, 
    data = train_data)

Residuals:
    Min      1Q  Median      3Q     Max 
-9564.2  -774.3     0.3   768.2  9130.2 

Coefficients:
                             Estimate Std. Error t value Pr(>|t|)    
(Intercept)                -1.032e+01  5.761e+01  -0.179    0.858    
satisfaction_score          2.620e+00  5.533e+00   0.473    0.636    
age                         9.575e-01  1.283e+00   0.746    0.456    
income                      3.502e-01  4.426e-04 791.219   <2e-16 ***
education_numeric          -1.823e+00  4.526e+00  -0.403    0.687    
region_numeric             -2.013e+00  5.230e+00  -0.385    0.700    
loyalty_numeric            -7.310e+00  9.605e+00  -0.761    0.447    
purchase_frequency_numeric -3.032e+00  7.362e+00  -0.412    0.680    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1521 on 69994 degrees of freedom
Multiple R-squared:  0.8994,    Adjusted R-squared:  0.8994 
F-statistic: 8.944e+04 on 7 and 69994 DF,  p-value: < 2.2e-16

ResidualvsFitted Plot and Q_Q Residual Plot

Transforming Model

Estimated transformation parameter 
       Y1 
0.6195993 

Fitting our model


Call:
lm(formula = purchase_amount^0.5 ~ satisfaction_score + age + 
    income + education_numeric + region_numeric + loyalty_numeric + 
    purchase_frequency_numeric + product_category_numeric, data = train_data)

Residuals:
    Min      1Q  Median      3Q     Max 
-48.540  -5.061   0.208   5.298  36.182 

Coefficients:
                             Estimate Std. Error t value Pr(>|t|)    
(Intercept)                 4.248e+01  3.001e-01 141.565   <2e-16 ***
satisfaction_score          1.647e-02  2.826e-02   0.583    0.560    
age                         5.853e-03  6.554e-03   0.893    0.372    
income                      1.898e-03  2.260e-06 839.731   <2e-16 ***
education_numeric          -3.158e-02  2.311e-02  -1.366    0.172    
region_numeric             -2.451e-03  2.671e-02  -0.092    0.927    
loyalty_numeric            -4.567e-02  4.905e-02  -0.931    0.352    
purchase_frequency_numeric -2.979e-03  3.760e-02  -0.079    0.937    
product_category_numeric   -1.993e-02  1.654e-02  -1.205    0.228    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 7.77 on 69993 degrees of freedom
Multiple R-squared:  0.9097,    Adjusted R-squared:  0.9097 
F-statistic: 8.815e+04 on 8 and 69993 DF,  p-value: < 2.2e-16

ResidualvsFitted Plot and Q_Q Residual Plot

Fixing Heteroscedasticity

Model: \(\text{Purchase Amount}^{0.5} = \beta_0 + \beta_1 \cdot \text{Satisfaction Score} + \beta_2 \cdot \text{Age} + \beta_3 \cdot \text{Income} + \beta_4 \cdot \text{Education} + \beta_5 \cdot \text{Region} + \beta_6 \cdot \text{Loyalty Status} + \beta_7 \cdot \text{Purchase Frequency} + \varepsilon\)

Fitted Model: \(\text{Purchase Amount}^{0.5} = \beta_0 + \beta_1 \cdot \text{Satisfaction Score} + \beta_2 \cdot \text{Age} + \beta_3 \cdot \text{Income} + \beta_4 \cdot \text{Education} + \beta_5 \cdot \text{Region} + \beta_6 \cdot \text{Loyalty Status} + \beta_7 \cdot \text{Purchase Frequency}\)


Call:
lm(formula = purchase_amount^0.5 ~ satisfaction_score + age + 
    income + education_numeric + region_numeric + loyalty_numeric + 
    purchase_frequency_numeric + product_category_numeric, data = train_data, 
    weights = 1/(fitted(lm_TRANS)^2))

Weighted Residuals:
     Min       1Q   Median       3Q      Max 
-0.38585 -0.05514  0.00238  0.05736  0.31041 

Coefficients:
                             Estimate Std. Error t value Pr(>|t|)    
(Intercept)                 3.926e+01  2.685e-01 146.224   <2e-16 ***
satisfaction_score         -5.144e-03  2.552e-02  -0.202    0.840    
age                         4.120e-03  5.924e-03   0.695    0.487    
income                      2.028e-03  2.170e-06 934.670   <2e-16 ***
education_numeric          -4.094e-02  2.089e-02  -1.960    0.050 *  
region_numeric              5.875e-03  2.414e-02   0.243    0.808    
loyalty_numeric            -3.311e-02  4.422e-02  -0.749    0.454    
purchase_frequency_numeric  1.371e-02  3.391e-02   0.404    0.686    
product_category_numeric   -2.100e-02  1.490e-02  -1.409    0.159    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.08299 on 69993 degrees of freedom
Multiple R-squared:  0.9258,    Adjusted R-squared:  0.9258 
F-statistic: 1.092e+05 on 8 and 69993 DF,  p-value: < 2.2e-16

ResidualvsFitted Plot and Q_Q Residual Plot

Model Selection

Model: \(\text{Purchase Amount}^{0.5} = 39.21 + 0.00203 \cdot \text{Income} - 0.03754 \cdot \text{Education} + 0.05591 \cdot \text{Purchase Frequency} - 0.0333 \cdot \text{Product Category} + \varepsilon\)

Fitted Model: \(\text{Purchase Amount}^{0.5} = 39.21 + 0.00203 \cdot \text{Income} - 0.03754 \cdot \text{Education} + 0.05591 \cdot \text{Purchase Frequency} - 0.0333 \cdot \text{Product Category}\)

Start:  AIC=-348474.3
purchase_amount^0.5 ~ satisfaction_score + age + income + education_numeric + 
    region_numeric + loyalty_numeric + purchase_frequency_numeric + 
    product_category_numeric

                             Df Sum of Sq    RSS     AIC
- satisfaction_score          1       0.0  482.0 -348476
- region_numeric              1       0.0  482.0 -348476
- purchase_frequency_numeric  1       0.0  482.0 -348476
- age                         1       0.0  482.0 -348476
- loyalty_numeric             1       0.0  482.0 -348476
- product_category_numeric    1       0.0  482.0 -348474
<none>                                     482.0 -348474
- education_numeric           1       0.0  482.0 -348472
- income                      1    6016.1 6498.1 -166380

Step:  AIC=-348476.2
purchase_amount^0.5 ~ age + income + education_numeric + region_numeric + 
    loyalty_numeric + purchase_frequency_numeric + product_category_numeric

                             Df Sum of Sq    RSS     AIC
- region_numeric              1       0.0  482.0 -348478
- purchase_frequency_numeric  1       0.0  482.0 -348478
- age                         1       0.0  482.0 -348478
- loyalty_numeric             1       0.0  482.0 -348478
- product_category_numeric    1       0.0  482.0 -348476
<none>                                     482.0 -348476
- education_numeric           1       0.0  482.0 -348474
- income                      1    6016.3 6498.3 -166380

Step:  AIC=-348478.2
purchase_amount^0.5 ~ age + income + education_numeric + loyalty_numeric + 
    purchase_frequency_numeric + product_category_numeric

                             Df Sum of Sq    RSS     AIC
- purchase_frequency_numeric  1       0.0  482.0 -348480
- age                         1       0.0  482.0 -348480
- loyalty_numeric             1       0.0  482.0 -348480
- product_category_numeric    1       0.0  482.0 -348478
<none>                                     482.0 -348478
- education_numeric           1       0.0  482.0 -348476
- income                      1    6016.5 6498.5 -166380

Step:  AIC=-348480
purchase_amount^0.5 ~ age + income + education_numeric + loyalty_numeric + 
    product_category_numeric

                           Df Sum of Sq    RSS     AIC
- age                       1       0.0  482.0 -348482
- loyalty_numeric           1       0.0  482.0 -348481
- product_category_numeric  1       0.0  482.0 -348480
<none>                                   482.0 -348480
- education_numeric         1       0.0  482.0 -348478
- income                    1    6016.5 6498.5 -166381

Step:  AIC=-348481.5
purchase_amount^0.5 ~ income + education_numeric + loyalty_numeric + 
    product_category_numeric

                           Df Sum of Sq    RSS     AIC
- loyalty_numeric           1       0.0  482.0 -348483
- product_category_numeric  1       0.0  482.0 -348482
<none>                                   482.0 -348482
- education_numeric         1       0.0  482.0 -348480
- income                    1    6016.5 6498.5 -166383

Step:  AIC=-348483
purchase_amount^0.5 ~ income + education_numeric + product_category_numeric

                           Df Sum of Sq    RSS     AIC
- product_category_numeric  1       0.0  482.0 -348483
<none>                                   482.0 -348483
- education_numeric         1       0.0  482.0 -348481
- income                    1    6016.5 6498.5 -166385

Step:  AIC=-348483
purchase_amount^0.5 ~ income + education_numeric

                    Df Sum of Sq    RSS     AIC
<none>                            482.0 -348483
- education_numeric  1       0.0  482.1 -348481
- income             1    6016.6 6498.6 -166387

Call:
lm(formula = purchase_amount^0.5 ~ income + education_numeric, 
    data = train_data, weights = 1/(fitted(lm_TRANS)^2))

Weighted Residuals:
     Min       1Q   Median       3Q      Max 
-0.38562 -0.05511  0.00239  0.05736  0.31076 

Coefficients:
                    Estimate Std. Error t value Pr(>|t|)    
(Intercept)        3.925e+01  7.659e-02 512.457   <2e-16 ***
income             2.028e-03  2.169e-06 934.722   <2e-16 ***
education_numeric -4.108e-02  2.089e-02  -1.967   0.0492 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.08298 on 69999 degrees of freedom
Multiple R-squared:  0.9258,    Adjusted R-squared:  0.9258 
F-statistic: 4.369e+05 on 2 and 69999 DF,  p-value: < 2.2e-16

Plot Model Selection

Prediction vs Actual

   id purchase_amount predicted_purchase_amount
1   1           18249                 14811.544
2   2            4557                  4931.719
3   3           11822                 13920.628
7   7            3293                  3132.324
10 10            8779                  7946.495
13 13            2450                  2781.652