Skip to content

Repository files navigation

E-commerce Customer Behavior Analysis

Dự án phân tích hành vi khách hàng E-commerce sử dụng dataset Online Retail từ Kaggle/UCI với RFM Analysis, Cohort Analysis và triển khai trên Excel & Power BI.

🎯 Mục tiêu dự án

  • Tạo cơ sở dữ liệu PostgreSQL với các bảng customers, transactions, products
  • Thực hiện phân tích RFM (Recency, Frequency, Monetary) để phân khúc khách hàng
  • Thực hiện Cohort Analysis để phân tích retention rate
  • Tạo các visualizations và heatmaps để hiển thị insights
  • Triển khai Excel dashboards với charts và pivot tables
  • Triển khai Power BI interactive dashboards với advanced analytics

🏗️ Cấu trúc dự án

E-commerce Customer Behavior/
├── data/
│   ├── raw/                    # Dữ liệu gốc từ Kaggle
│   ├── processed/              # Dữ liệu đã xử lý (Excel files)
│   └── powerbi/                # Dữ liệu tối ưu cho Power BI
├── sql/
│   ├── create_tables.sql       # Script tạo bảng
│   ├── rfm_analysis.sql        # Query RFM Analysis
│   └── cohort_analysis.sql     # Query Cohort Analysis
├── notebooks/
│   ├── data_preprocessing.ipynb # Tiền xử lý dữ liệu
│   ├── rfm_analysis.ipynb      # Phân tích RFM
│   └── cohort_analysis.ipynb   # Phân tích Cohort
├── scripts/
│   ├── create_excel_analysis.py     # Tạo Excel basic analysis
│   ├── create_advanced_excel.py     # Tạo Excel advanced metrics
│   ├── create_excel_dashboard.py    # Tạo Excel với charts
│   └── create_powerbi_export.py     # Xuất dữ liệu cho Power BI
├── docs/
│   ├── Excel_Analysis_Guide.md      # Hướng dẫn phân tích Excel
│   ├── PowerBI_Implementation_Guide.md  # Hướng dẫn triển khai Power BI
│   └── PowerBI_DAX_Measures.md      # Template DAX measures
├── src/
│   └── utils/
│       └── db_connection.py    # Class kết nối database
├── docker/
│   └── docker-compose.yml     # Docker setup cho PostgreSQL
├── open_excel_analysis.bat    # Quick launcher cho Excel
├── open_powerbi_setup.bat     # Quick launcher cho Power BI
└── requirements.txt           # Python dependencies

🚀 Hướng dẫn sử dụng

Bước 1: Chuẩn bị môi trường

  1. Clone repository và cài đặt dependencies:

    pip install -r requirements.txt
  2. Khởi động PostgreSQL với Docker:

    cd docker
    docker-compose up -d
  3. Tải dataset:

    • Tải file online_retail.csv từ Kaggle
    • Đặt vào thư mục data/raw/

Bước 2: Thực hiện phân tích

📊 Python Notebooks Analysis

  1. Data Preprocessing:

    • Mở notebooks/data_preprocessing.ipynb
    • Chạy từng cell để load, clean và import dữ liệu vào PostgreSQL
  2. RFM Analysis:

    • Mở notebooks/rfm_analysis.ipynb
    • Thực hiện phân khúc khách hàng dựa trên RFM scores
  3. Cohort Analysis:

    • Mở notebooks/cohort_analysis.ipynb
    • Phân tích retention rate theo cohorts

� Excel Analysis

  1. Tạo Excel Analysis Files:

    # Tạo 3 loại Excel files
    python scripts/create_excel_analysis.py      # Basic analysis
    python scripts/create_advanced_excel.py      # Advanced metrics
    python scripts/create_excel_dashboard.py     # Interactive dashboard
  2. Mở Excel Analysis:

    • Double-click open_excel_analysis.bat
    • Chọn loại file Excel muốn mở (Basic/Advanced/Dashboard)

📊 Power BI Implementation

  1. Chuẩn bị dữ liệu cho Power BI:

    python scripts/create_powerbi_export.py
  2. Thiết lập Power BI:

    • Double-click open_powerbi_setup.bat
    • Import CSV files từ data/powerbi/ folder
    • Tham khảo docs/PowerBI_Implementation_Guide.md để setup dashboard

�🛠️ Công nghệ sử dụng

  • Database: PostgreSQL (Docker)
  • Python Libraries:
    • pandas, numpy (Data manipulation)
    • matplotlib, seaborn, plotly (Visualization)
    • psycopg2, sqlalchemy (Database connection)
    • jupyter (Notebooks)
    • xlsxwriter, openpyxl (Excel export)
  • Business Intelligence:
    • Microsoft Excel (Charts, Pivot Tables, Dashboards)
    • Microsoft Power BI (Interactive dashboards, DAX measures)

📊 Kết quả và deliverables

1. Python Analysis

  • RFM Analysis: 11 customer segments với detailed insights
  • Cohort Analysis: Retention heatmaps và performance metrics
  • Visualizations: 3D plots, heatmaps, interactive charts

2. Excel Analysis

  • 3 Excel Files:

    • online_retail_analysis.xlsx - Basic analysis với 8 sheets
    • online_retail_advanced_analysis.xlsx - Advanced metrics & growth rates
    • online_retail_dashboard.xlsx - Interactive charts & formatted dashboards
  • Excel Features:

    • Executive dashboard với KPIs
    • Customer segmentation với RFM scores
    • Product ABC classification
    • Geographic performance analysis
    • Monthly trend analysis với growth rates
    • Ready-to-use Pivot Tables và Charts

3. Power BI Implementation

  • 7 Optimized CSV Files:

    • sales_data.csv - Main fact table (397K records)
    • customers.csv - Customer dimension (4.3K records)
    • products.csv - Product dimension với ABC classification
    • countries.csv - Geographic dimension
    • date_dimension.csv - Complete date dimension
    • rfm_analysis.csv - Customer segmentation
    • monthly_summary.csv - Pre-aggregated metrics
  • Power BI Components:

    • Complete DAX measures template
    • Data model relationships guide
    • 4 Main dashboard views (Executive, Customer, Product, Geographic)
    • Advanced analytics với time intelligence
    • Mobile-optimized layouts

🎯 Business Insights

RFM Segmentation Results

Customer Segment Distribution:
- Champions: 110 customers (2.54%) - Top performers
- Loyal Customers: 363 customers (8.37%) - Consistent buyers
- Potential Loyalists: 799 customers (18.42%) - Growth opportunity
- At Risk: 297 customers (6.85%) - Need attention
- Lost: 1,733 customers (39.95%) - Win-back campaigns

Cohort Retention Analysis

Average Retention Rates:
- Month 1: 85.2%
- Month 3: 45.8%
- Month 6: 28.3%
- Month 12: 18.7%

Key Performance Metrics

Business KPIs:
- Total Revenue: $8.9M
- Total Customers: 4,338
- Average Order Value: $22.74
- Customer Lifetime Value: $2,048.69
- Active Markets: 37 countries

🔗 Database Connection

  • PostgreSQL: localhost:5432
  • Database: ecommerce_db
  • Username: admin
  • Password: password123
  • pgAdmin: http://localhost:8080

📖 Documentation

  • Excel Analysis: docs/Excel_Analysis_Guide.md
  • Power BI Setup: docs/PowerBI_Implementation_Guide.md
  • DAX Measures: docs/PowerBI_DAX_Measures.md

🎯 Kỹ năng đạt được

  • SQL: JOIN, Aggregation, Window functions, CTEs
  • Customer Analytics: RFM modeling, Cohort analysis, Customer segmentation
  • Data Visualization: Heatmaps, interactive plots, business dashboards
  • Business Intelligence: Excel advanced features, Power BI development
  • Database Management: PostgreSQL, Docker
  • Programming: Python data analysis, automation scripts

📝 Ghi chú

  • Đảm bảo Docker đã được cài đặt và chạy
  • Dataset gốc có khoảng 500K+ records
  • Excel files được tối ưu cho performance (sample data)
  • Power BI files hỗ trợ real-time refresh
  • Tất cả visualizations và analysis được document đầy đủ

🤝 Đóng góp

Mọi đóng góp và cải thiện đều được chào đón! Vui lòng tạo issue hoặc pull request.


Nguồn dữ liệu: Online Retail Dataset - Kaggle

📊 Kết quả mong đợi

RFM Analysis

  • Phân khúc khách hàng thành 11 nhóm (Champions, Loyal Customers, At Risk, etc.)
  • Visualizations: 3D scatter plots, heatmaps, segment distribution
  • Insights và recommendations cho từng segment

Cohort Analysis

  • Retention heatmap theo tháng
  • Retention curves và performance comparison
  • Insights về customer lifetime và churn patterns

🎯 Kỹ năng đạt được

  • SQL: JOIN, Aggregation, Window functions, CTEs
  • Customer Analytics: RFM modeling, Cohort analysis
  • Data Visualization: Heatmaps, interactive plots
  • Database Management: PostgreSQL, Docker

📈 Sample Outputs

RFM Segmentation

Customer Segment Summary:
- Champions: 500 customers (15.2%)
- Loyal Customers: 800 customers (24.3%)
- At Risk: 300 customers (9.1%)
...

Cohort Retention

Average Retention Rates:
- Month 1: 85.2%
- Month 3: 45.8%
- Month 6: 28.3%
- Month 12: 18.7%

🔗 Kết nối Database

  • PostgreSQL: localhost:5432
  • Database: ecommerce_db
  • Username: admin
  • Password: password123
  • pgAdmin: http://localhost:8080

📝 Ghi chú

  • Đảm bảo Docker đã được cài đặt và chạy
  • Dataset gốc có khoảng 500K+ records
  • Thời gian xử lý có thể mất vài phút cho large datasets
  • Tất cả visualizations được lưu trong notebooks

🤝 Đóng góp

Mọi đóng góp và cải thiện đều được chào đón! Vui lòng tạo issue hoặc pull request.


Nguồn dữ liệu: Online Retail Dataset - Kaggle

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages