An unsupervised machine learning project that groups retail customers according to their annual income and spending score. The resulting segments can support targeted marketing, customer retention, and purchasing-pattern analysis.
- Overview
- Project Objective
- Technologies Used
- Methodology
- Dataset
- Project Structure
- Requirements
- Setup
- How to Run
- Results
- Customer Segments
- Learning Outcomes
- Future Improvements
- Author
- Internship Details
This project is part of the SkillCraft Technology Machine Learning Internship and uses K-Means clustering to identify groups of customers with similar income and spending behavior.
Workflow:
- Load and inspect the Mall Customers dataset
- Select annual income and spending score as clustering features
- Use the Elbow Method to estimate the number of clusters
- Train a K-Means model with five clusters
- Visualize clusters and their centroids
- Export the clustered customer data to CSV
Segment customers into meaningful groups using Annual Income (k$) and Spending Score (1-100), then interpret those groups for business decision-making.
- Python 3
- Pandas
- NumPy
- Scikit-learn
- Matplotlib
- K-Means clustering
- Load the customer data from
data/Mall_Customers.csv. - Select the income and spending-score columns.
- Calculate WCSS for values of
kfrom 1 to 10. - Apply the Elbow Method to select the cluster count.
- Fit K-Means with
random_state=42andn_init=10. - Label clusters using their centroid income and spending levels.
- Save a combined Elbow Method and segmentation plot.
- Export the results with cluster labels to a CSV file.
The project uses the Mall Customers dataset. The model uses these two features:
| Feature | Description |
|---|---|
Annual Income (k$) |
Customer annual income in thousands of dollars |
Spending Score (1-100) |
Customer spending score |
The dataset contains 200 customer records. If the local CSV is unavailable, the script creates a reproducible sample dataset so it can still be executed.
SCT_ML_2/
├── README.md
├── kmeans_clustering.py
├── data/
│ └── Mall_Customers.csv
├── customer_segments_plot.png
└── segmented_customers.csv
Python 3.9 or later is recommended. Install the dependencies with:
pip install pandas numpy matplotlib scikit-learncd "SCT_ML 2"Windows PowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1Windows Command Prompt:
python -m venv .venv
.venv\Scripts\activate.batpip install pandas numpy matplotlib scikit-learnpython kmeans_clustering.pyThe script:
- prints dataset and cluster information
- saves
customer_segments_plot.png - saves clustered data to
segmented_customers.csv
The model divides the customers into five clusters and produces a plot containing both the Elbow Method curve and the customer segments. Each point represents a customer, while the marked centroids represent the center of each cluster.
- Target: High income, high spending customers
- Careful: High income, low spending customers
- Standard: Moderate income and moderate spending customers
- Careless: Low income, high spending customers
- Sensible: Low income, low spending customers
- Understanding unsupervised learning and K-Means clustering
- Selecting the number of clusters with WCSS and the Elbow Method
- Applying feature selection to a distance-based algorithm
- Interpreting cluster centroids
- Visualizing customer groups and exporting predictions
- Scale features before clustering and compare the results
- Evaluate the solution using silhouette score
- Add demographic features such as age and gender
- Build an interactive dashboard for segment exploration
Devarakonda Vignesh Varsha
| Detail | Information |
|---|---|
| Internship | SkillCraft Technology |
| Domain | Machine Learning |
| Task | Task 02 - Customer Segmentation using K-Means Clustering |
| Clusters | 5 |
Built with ❤️ during SkillCraft Technology ML Internship