Skip to content

Latest commit

 

History

History
81 lines (58 loc) · 2.18 KB

File metadata and controls

81 lines (58 loc) · 2.18 KB

Saved Models

This folder contains the two serialised files needed to score new customers without retraining.


Files

kmeans_customer_segmentation.pkl

The trained K-Means model with K=4 fitted on the full RFM dataset.

  • Algorithm: sklearn.cluster.KMeans
  • n_clusters: 4
  • random_state: 42
  • n_init: 10
  • max_iter: 300
  • Silhouette Score: ~0.38

rfm_standard_scaler.pkl

The fitted StandardScaler used to preprocess RFM features before clustering.

  • Algorithm: sklearn.preprocessing.StandardScaler
  • Features scaled: Recency, Frequency, Monetary
  • Fitted on: the full cleaned RFM customer dataset (~4,300 customers)

Important: Always use this exact scaler — never refit on new data. The scaler must apply the same mean and std from training for cluster assignments to be valid.


Cluster Labels

Cluster ID Segment Name Profile
Varies Champions Low Recency, High Frequency, High Monetary
Varies Loyal Customers Medium R/F/M across all three
Varies New Customers Low Recency, Low Frequency, Low Monetary
Varies At-Risk High Recency, Low Frequency, Low Monetary

The cluster ID numbers (0–3) mapped to segment names depend on the data. See the notebook (Cell 253) for the dynamic label mapping logic.


Usage Example

import joblib
import pandas as pd

# Load saved artefacts
model  = joblib.load('models/kmeans_customer_segmentation.pkl')
scaler = joblib.load('models/rfm_standard_scaler.pkl')

# Define a new customer's RFM values
new_customer = pd.DataFrame({
    'Recency':   [10],    # days since last purchase
    'Frequency': [8],     # number of unique orders
    'Monetary':  [450.0]  # total spend in GBP
})

# Scale using the training scaler
scaled = scaler.transform(new_customer)

# Predict cluster
cluster_id = model.predict(scaled)[0]
print(f'Assigned cluster: {cluster_id}')
# Map cluster_id to segment name using label_map from the notebook

Regenerating the Models

If you want to retrain from scratch:

  1. Open notebooks/Myntra_Customer_Segmentation.ipynb
  2. Run all cells (Kernel → Restart & Run All)
  3. The joblib.dump() calls in Section 8 will overwrite these files