Understanding customer behavior is crucial for retail success. This project analyzes shopping data from Istanbul to identify distinct customer segments, enabling:
- Targeted marketing campaigns - Reach the right customers with the right message
- Personalized customer experiences - Tailor offerings to specific customer needs
- Optimized inventory management - Stock products based on customer preferences
- Strategic business decisions - Data-driven insights for growth
- Performs exploratory data analysis on Istanbul shopping data
- Identifies customer segments using clustering algorithms
- Analyzes shopping patterns and trends
- Provides actionable business insights
- Visualizes customer behavior patterns
- ποΈ Customer purchasing patterns - Understanding what drives purchases
- π° Spending behavior analysis - Identifying high-value customers
- π Demographic segmentation - Targeting by age, gender, and income
- π Temporal shopping trends - Peak times and seasonal patterns
- π― Customer lifetime value estimation - Predicting long-term value
Source: Istanbul Shopping Mall Customer Data
Customer Demographics:
- Age
- Gender
- Income level
- Location
Shopping Behavior:
- Purchase amount
- Product categories
- Shopping frequency
- Payment methods
- Visit duration
Temporal Data:
- Purchase date/time
- Seasonal patterns
- Day of week trends
Dataset Characteristics:
- Comprehensive customer transaction records
- Multiple demographic and behavioral variables
- Suitable for segmentation and pattern analysis
# Data cleaning and preprocessing
- Handling missing values
- Feature engineering
- Outlier detection and treatment
- Data normalization/standardization- Univariate analysis (distributions)
- Bivariate analysis (relationships)
- Correlation analysis
- Statistical testing
- Visualization of patterns
- RFM Analysis (Recency, Frequency, Monetary)
- Customer lifetime value calculation
- Shopping pattern indicators
- Temporal features
- Derived metrics
- K-Means Clustering: Identify natural customer groups
- Hierarchical Clustering: Understand segment relationships
- DBSCAN: Detect outliers and dense regions
- PCA: Dimensionality reduction and visualization
- Demographic characteristics
- Shopping behavior patterns
- Value contribution
- Growth potential
- Marketing recommendations
Python 3.9+
βββ Data Manipulation
β βββ pandas
β βββ numpy
β βββ scipy
βββ Machine Learning
β βββ scikit-learn
β βββ yellowbrick
βββ Visualization
β βββ matplotlib
β βββ seaborn
β βββ plotly
β βββ folium (for maps)
βββ Jupyter
βββ jupyter notebook
- Python 3.9 or higher
- pip package manager
- 4GB RAM minimum
# Clone the repository
git clone https://github.com/Ghulam-Mustafa-Keerio/Customer-Segmentation-Analysis.git
cd Customer-Segmentation-Analysis
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Launch Jupyter Notebook
jupyter notebook
# Open Customer_Segmentation_Analysis.ipynb1. Load and Explore Data:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Load dataset
df = pd.read_csv('data/istanbul_shopping_data.csv')
# Quick overview
print(df.head())
print(df.info())
print(df.describe())2. Perform RFM Analysis:
# Calculate RFM scores
# Recency: Days since last purchase
# Frequency: Number of transactions
# Monetary: Total spending amount
rfm_df = calculate_rfm(df,
customer_id='CustomerID',
date='InvoiceDate',
amount='TotalAmount')3. Apply Clustering:
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
# Prepare features
features = ['Recency', 'Frequency', 'Monetary']
X = rfm_df[features]
# Standardize
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
# Apply K-Means
kmeans = KMeans(n_clusters=4, random_state=42)
rfm_df['Segment'] = kmeans.fit_predict(X_scaled)4. Visualize Segments:
import plotly.express as px
# 3D scatter plot of segments
fig = px.scatter_3d(rfm_df,
x='Recency',
y='Frequency',
z='Monetary',
color='Segment',
title='Customer Segments')
fig.show()- Characteristics: High frequency, recent purchases, high spending
- Action: VIP treatment, loyalty rewards, exclusive access
- Business Value: Highest lifetime value customers
- Characteristics: Regular purchasers, moderate to high spending
- Action: Engagement programs, upselling, personalized offers
- Business Value: Stable revenue stream
- Characteristics: Recent customers, growing purchase frequency
- Action: Nurture with offers, build loyalty programs
- Business Value: High growth potential
- Characteristics: Previously active, now declining engagement
- Action: Win-back campaigns, incentives, feedback surveys
- Business Value: Retention opportunity
- π Peak shopping periods identified for optimal marketing timing
- π Time-of-day patterns for staffing and promotions
- π³ Payment preferences for checkout optimization
- π Average basket analysis for upselling strategies
- π Seasonal variations for inventory planning
The project includes comprehensive visualizations:
- Age and gender demographics
- Income level distribution
- Geographic heat maps
- Purchase frequency over time
- Spending trends
- Category preferences
- Time-of-day analysis
- 3D cluster visualization
- Dendrogram (hierarchical clustering)
- Elbow curve for optimal K
- Silhouette analysis
- Revenue by segment
- Customer lifetime value
- Churn risk indicators
- Growth opportunities
- β Exclusive early access to new products
- β Premium customer service
- β Referral incentive programs
- β Personalized communication
- β Points-based loyalty program
- β Special birthday offers
- β Community building initiatives
- β Product recommendations
- β Welcome series emails
- β Educational content
- β First purchase follow-ups
- β Incentivized repeat purchases
- β Re-engagement campaigns
- β Limited-time offers
- β Feedback surveys
- β Win-back discounts
Customer-Segmentation-Analysis/
βββ Customer_Segmentation_Analysis.ipynb # Main analysis notebook
βββ data/ # Data directory (if applicable)
β βββ raw/ # Raw data files
β βββ processed/ # Processed data files
βββ requirements.txt # Python dependencies
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE # MIT License
- Recency (R): Days since last purchase
- Frequency (F): Number of transactions
- Monetary (M): Total spending amount
- Each metric scored 1-5
- Combined RFM score (111-555)
- Segment assignment based on scores
- Elbow method for optimal K
- Silhouette score analysis
- Davies-Bouldin index
- Calinski-Harabasz score
Technical Skills:
- β Data cleaning and preprocessing
- β Exploratory data analysis
- β Feature engineering
- β Unsupervised learning (clustering)
- β Statistical analysis
- β Data visualization
- β Python programming
Business Skills:
- Customer behavior analysis
- Marketing strategy development
- Data-driven decision making
- Retail analytics
- Customer relationship management
Advanced Techniques:
- Dimensionality reduction (PCA, t-SNE)
- Multiple clustering algorithms comparison
- Hyperparameter tuning
- Statistical significance testing
- Time series analysis for trends
- πΊοΈ Geographic analysis of Istanbul shopping zones
- π± Product category deep-dive
- π‘ Actionable marketing recommendations
- π Interactive visualizations
- π Customer lifetime value analysis
- π― Churn prediction indicators
Planned Improvements:
- Predictive modeling for customer churn
- Real-time dashboard with Streamlit
- A/B testing framework
- Integration with CRM systems
- Recommendation engine
- Market basket analysis
- Cohort analysis
- Customer journey mapping
Contributions are welcome! Ways to contribute:
- Add new clustering algorithms
- Improve visualizations
- Enhance documentation
- Add more business metrics
- Optimize code performance
See CONTRIBUTING.md for details.
- Customer Segmentation
- RFM Analysis
- Clustering Algorithms
- Retail Analytics
This project is licensed under the MIT License - see the LICENSE file for details.
- Istanbul shopping mall data providers
- Data science community
- Open-source contributors
- Researchers and analysts using this project
Ghulam Mustafa Keerio
- GitHub: @Ghulam-Mustafa-Keerio
- Specialization: Data Science, Machine Learning, Business Analytics
- Focus: Turning data into actionable insights
Have questions or suggestions?
- Open an Issue
- Submit a Pull Request
- Connect on LinkedIn
- Data collection and cleaning
- Exploratory data analysis
- Feature engineering
- Clustering implementation
- Visualization and reporting
- Dashboard development
- Deployment
"Data is the new oil, but insights are the refined fuel that drives business growth."
This project serves as a valuable resource for researchers, data analysts, and machine learning enthusiasts who want to gain insights into shopping trends and patterns in Istanbul.