Skip to content

About

An end-to-end Python ETL data pipeline processing Walmart's e-commerce and retail sales data to evaluate macroeconomic and holiday sales trends.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

Retail Sales & Supply-Chain Data Pipeline

Overview

This repository contains an end-to-end Machine Learning Engineering pipeline for ingestion, transformation, store segmentation, and baseline forecasting of retail sales data across multiple store locations and departments.

The pipeline handles disparate data sources—combining relational database records (PostgreSQL) with binary storage files (Parquet)—and performs automated cleaning, store clustering, feature engineering, and model evaluation.

Even with baseline results, this project demonstrates real-world ML engineering fundamentals: robust data extraction and transformation (ETL), leakage-free feature scaling, clustering-based segmentation, and structured diagnostic evaluation.


## Project Architecture

PostgreSQL Database (grocery_sales)  +  Parquet Data Store (extra_data.parquet)
                                  |
                                  v
                       [ ETL Data Pipeline ]
                       - Merge on Index
                       - Null Imputation (Mean)
                       - Date Transformation
                       - Sales Threshold Filtering
                                  |
                                  v
                      [ Clean Data Export ]
               (clean_data.csv / agg_data.csv)
                                  |
                                  v
                  [ Store Segmentation (K-Means) ]
                       - Mean & Median Sales
                       - Store Size Feature Scaling
                                  |
                                  v
                 [ Predictive Modeling (XGBoost) ]
                       - Log-Transformed Target
                       - Train/Test Split Evaluation

Data Dictionary

Variable Source Data Type Description
Store_ID PostgreSQL Categorical / INT Unique store identifier
Dept PostgreSQL Categorical / INT Department number within a store
Weekly_Sales PostgreSQL Continuous / FLOAT Target variable ($)
IsHoliday PostgreSQL Boolean Flag indicating holiday week
CPI Parquet Continuous / FLOAT Consumer Price Index
Unemployment Parquet Continuous / FLOAT Regional unemployment rate
Size PostgreSQL Continuous / INT Store footprint in square feet
Cluster_ID Engineered Categorical / INT K-Means assigned segment (0–N)

Key Features

  • Heterogeneous Data Ingestion: Extracts tabular grocery sales data from PostgreSQL and merges it with complementary economic/promotional data from Parquet files.
  • Robust Transformation Pipeline:
    • Imputes missing values (CPI, Unemployment, Weekly_Sales) using feature averages.
    • Filters low-volume sales data (Weekly_Sales > $10,000) for data consistency.
    • Computes aggregated monthly revenue metrics.
  • Store Clustering & Feature Engineering:
    • Groups stores using K-Means clustering based on store size and historical sales distribution metrics.
    • Adds engineered features such as cluster IDs and store-level statistical summaries.
  • Baseline Modeling & Diagnostics:
    • Trains a gradient boosting regressor using log-transformed target variables (log1p).
    • Reports regression metrics (MAE, RMSE) and feature importance rankings.

Pipeline Execution & Output

1. Data Cleaning & Aggregation

Running the ETL stage ingests raw SQL and Parquet tables, resolves null values, and produces two consolidated data artifacts:

  • clean_data.csv: Granular dataset containing cleaned features (Store_ID, Month, Dept, IsHoliday, Weekly_Sales, CPI, Unemployment).
  • agg_data.csv: Aggregated monthly revenue and volume metrics used for macro-level trend inspection.

2. Model Performance Summary

  • Mean Absolute Error (MAE): 758.93
  • Root Mean Squared Error (RMSE): 793.80

3. Detailed Error Metric Analysis

Mean Absolute Error (MAE) — 758.93

  • Definition: MAE calculates the average magnitude of absolute errors across all test predictions, weighting every individual deviation equally.
  • Interpretation: On average, the model's predicted weekly sales deviate from actual sales by 758.93.
  • Business Context: Provides an intuitive baseline metric for operational planners to estimate expected cash-flow variance per store department.

Root Mean Squared Error (RMSE) — 793.80

  • Definition: RMSE squares errors before averaging, penalizing larger deviations more heavily than smaller ones before scaling back to the original unit.
  • Interpretation: An RMSE of $793.80 sits remarkably close to the MAE ($758.93), yielding a small delta of ~34.87.
  • Business Context: The narrow gap between RMSE and MAE indicates that the prediction errors are uniformly distributed. The model does not suffer from extreme runaway outliers or severe prediction spikes, making it predictable for supply chain risk assessment.

Feature Importance Analysis

Feature Importance Weight Description
Size 0.4838 Physical square footage of store location
Cluster_ID 0.4519 Segment assignment from K-Means clustering
Store 0.0642 Store identifier index
Temperature / CPI / Fuel_Price 0.0000 Macroeconomic and environmental factors

Key Insights & Diagnostic Observations

  • Dominance of Structural Features: Store physical capacity (Size) and store segment (Cluster_ID) account for over 93% of the predictive weight in the baseline model.
  • Macroeconomic Feature Impact: External indicators such as CPI, Unemployment, and Fuel_Price show zero baseline feature importance, indicating that temporal lag features or interaction terms are needed to capture their correlation with sales dynamics.

About

An end-to-end Python ETL data pipeline processing Walmart's e-commerce and retail sales data to evaluate macroeconomic and holiday sales trends.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages