Customer Personality Analysis: exploratory data analysis

Dataset source:

https://www.kaggle.com/datasets/whenamancodes/customer-personality-analysis

Place marketing_campaign.csv in the working directory.

The file is tab-delimited.

library(ggplot2)

marketing <- read.delim(
  "marketing_campaign.csv",
  header = TRUE,
  stringsAsFactors = FALSE,
  na.strings = c("", "NA")
)
# Original and analysis sample sizes

original_n <- nrow(marketing)
analysis_n <- 1120
eda <- marketing[1:analysis_n, , drop = FALSE]


# Create total product spending over the last two years

spending_columns <- c(
  "MntWines",
  "MntFruits",
  "MntMeatProducts",
  "MntFishProducts",
  "MntSweetProducts",
  "MntGoldProds"
)

eda$Total_Spending <- rowSums(
  eda[, spending_columns],
  na.rm = TRUE
)

summary(eda$Total_Spending)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     6.0    67.0   405.5   616.1  1064.2  2486.0
# EDA 1: Distribution of total customer spending

p1 <- ggplot(eda, aes(x = Total_Spending)) +
  geom_histogram(bins = 30) +
  labs(
    title = "Distribution of Total Customer Spending",
    x = "Total Spending",
    y = "Number of Customers"
  ) +
  theme_minimal()

p1

# EDA 2: Relationship between income and total spending

p2 <- ggplot(eda, aes(x = Income, y = Total_Spending)) +
  geom_point() +
  labs(
    title = "Income vs. Total Customer Spending",
    x = "Income",
    y = "Total Spending"
  ) +
  theme_minimal()

p2
## Warning: Removed 13 rows containing missing values or values outside the scale range
## (`geom_point()`).

cor(eda$Income, eda$Total_Spending, use = "complete.obs")
## [1] 0.7955831

The data collected indicated that overall customer spending was positively skewed; there were a number of customers who spent very little while there were few customers who spent large sums. The data also showed a strong positive association (correlation coefficient of approximately .80) between customers’ income and their total spending on products for which they made purchases from the sample.