Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Business Analytics with Python: Customer Churn Analysis

A Python portfolio project analyzing customer churn for a sporting goods retailer (DQLab Sport Center), using exploratory data analysis, data visualization, and a logistic regression model.

Originally published on Rose Data Scientist.

Background

DQLab Sport Center sells jackets, shirts, bags, and shoes, and has been operating since 2013. In 2019, the store manager noticed a decline in repeat customers and brought in a junior data analyst to investigate.

A customer is defined as churned if they have not made a purchase in the 6 months prior to the most recent data update (2018-08-01 is used as the cutoff date in this dataset).

Dataset

Transaction data from 2013–2019, ~100,000 rows, sourced from: https://storage.googleapis.com/dqlab-dataset/data_retail.csv

Column Description
No / Row_Num Row identifiers
Customer_ID Unique customer identifier
Product Product category (Jacket, Shirt, Bag, Shoes)
First_Transaction Timestamp of customer's first purchase
Last_Transaction Timestamp of customer's most recent purchase
Average_Transaction_Amount Average spend per transaction
Count_Transaction Total number of transactions

Project Structure

The analysis, in churn_analysis.py, follows this workflow:

  1. Data preparation

    • Import the CSV and inspect it
    • Convert Unix timestamps to datetime
    • Flag customers as churned/not churned based on the 6-month cutoff
    • Drop unneeded columns
  2. Data visualization

    • Customer acquisition trend by year (bar chart)
    • Transaction count trend by year (bar chart)
    • Average transaction amount by year, per product (point plot)
    • Churn proportion by product (pie charts)
    • Customer distribution by transaction count group (bar chart)
    • Customer distribution by average transaction amount group (bar chart)
  3. Predictive modeling

    • Feature engineering: Year_Diff (years between first and last transaction)
    • Features used: Average_Transaction_Amount, Count_Transaction, Year_Diff
    • Train/test split (75/25)
    • Logistic Regression model to predict churn
    • Evaluation via confusion matrix, accuracy, precision, and recall

Results

Metric Score
Accuracy 0.667
Precision 0.667
Recall 0.667

The model isn't strongly biased toward either class, suggesting the dataset is reasonably balanced for learning simple patterns — though there's clear room for improvement (e.g. additional features, different models, hyperparameter tuning).

Requirements

See requirements.txt. Core libraries: pandas, matplotlib, seaborn, scikit-learn, numpy.

License

MIT

About

Customer churn analysis in Python using pandas, matplotlib, and logistic regression — EDA, visualization, and predictive modeling for retail.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages