This project performs customer segmentation using the K-Means clustering algorithm. It applies unsupervised learning to categorize customers based on their annual income and spending score.
The project uses the Mall_Customers.csv dataset, which contains the following features:
- CustomerID: Unique ID assigned to each customer.
- Gender: Gender of the customer.
- Age: Age of the customer.
- Annual Income (K$): Annual income of the customer in thousands.
- Spending Score (1-100): Score assigned by the mall based on customer behavior and spending patterns.
Dataset Source: Kaggle - Mall Customers Dataset.
- K-Means Clustering:
- Determines the optimal number of clusters using the Elbow Method.
- Applies K-Means clustering to segment customers.
- Visualizes the clusters with a scatter plot.
Ensure you have Python installed along with the required dependencies:
-
Using
pipdirectly:pip install numpy pandas seaborn matplotlib scikit-learn
-
Using
requirements.txt(recommended):pip install -r requirements.txt
- Clone the repository:
git clone git@github.com:MoustafaMohamed01/Mall-Customer-Segmentation-Data.git cd Mall-Customer-Segmentation-Data - Place the Mall_Customers.csv file in the same directory as the script.
- Run the Python script:
python Customer_Segmentation_using_K-Means_Clustering.py
- Load Data: Reads the dataset into a Pandas DataFrame.
- Data Preprocessing: Extracts relevant features (Annual Income and Spending Score).
- Finding Optimal Clusters: Uses the Elbow Method to determine the best value of K.
- Clustering with K-Means: Applies K-Means with the optimal K value.
- Visualization: Plots the Elbow Graph and Cluster Scatter Plot.
The Elbow Method helps determine the optimal number of clusters by plotting the Within-Cluster Sum of Squares (WCSS).
The final K-Means clustering results are visualized in a scatter plot, showing customer segments and their centroids.
- The optimal number of clusters (K) is selected using the Elbow Method.
- Customers are grouped based on their Annual Income and Spending Score.
- Business insights can be derived by analyzing these segments (e.g., targeting high-spending customers with promotions).

