Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forest Cover Classification

Project re-upload notice (Jan 2026)

I got locked out of the original GitHub account that hosted this project. This repository is intended to be re-uploaded and maintained under my new GitHub account.

New canonical repo : https://github.com/agilap/Customer-Segmentation-Model

🧠 Customer Segmentation using RFM and K-Means

Reupload notice (2026-01-22): This project has been reuploaded to a new GitHub repository. Update the clone URL in the Getting Started section to match the new location.

Customer segmentation is a powerful way for businesses to understand and group their customers based on behavior. This project performs RFM Analysis (Recency, Frequency, Monetary) and uses K-Means Clustering to discover unique customer segments from retail transaction data.


📦 Dataset

  • File: Online Retail.xlsx
  • Description: Real-world online retail dataset containing transactions from 2010–2011.
  • Key Fields: CustomerID, InvoiceNo, InvoiceDate, Quantity, UnitPrice

🔁 Workflow Overview

🔹 1. Data Preprocessing

  • Removed rows with missing CustomerID
  • Filtered out transactions with negative Quantity or UnitPrice
  • Created a new column: TotalPrice = Quantity × UnitPrice

🔹 2. RFM Feature Engineering

  • Recency: Days since last purchase (from the most recent date)
  • Frequency: Number of unique purchases (InvoiceNo)
  • Monetary: Total spending per customer

🔹 3. Exploratory Data Analysis

🔍 Pairplot of RFM Features

Pairplot

📊 Correlation Heatmap

Heatmap


🔹 4. Clustering

📈 Elbow Method to Select Optimal K

Elbow Method

🟣 Silhouette Score Visualization

Silhouette

  • Optimal number of clusters (k) is chosen based on lowest inertia and silhouette evaluation.

🔹 5. Final Pipeline

  • Created a reusable scikit-learn pipeline with:
    • StandardScaler
    • KMeans
  • Trained on the RFM features and predicted segments across the dataset.

📤 Output

  • customer_segments.csv:
    • Contains: CustomerID, RFM metrics, assigned cluster
  • Use these segments to identify:
    • VIP customers
    • At-risk/dormant users
    • Frequent but low spenders
    • New or seasonal shoppers

🛠️ Tech Stack

  • Python 3
  • pandas, numpy, matplotlib, seaborn, yellowbrick
  • scikit-learn for clustering and pipeline
  • jupyter for interactive development

🚀 Getting Started

  1. Clone the repo
    git clone https://github.com/agilap/customer-segmentation.git
    cd customer-segmentation

2. Install dependencies
 ```bash
  pip install -r requirements.txt
  1. Place dataset in the project root.

  2. Run the script to generate visualizations and the final csv.

    python main.py

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages