This project analyzes weekly store-level sales using the Walmart Retail Dataset.
The dataset includes sales history, store metadata, and economic indicators such as CPI, Fuel Price, Temperature, and Unemployment.
All files (train.csv, features.csv, stores.csv) were merged into a unified analytical dataset.
Distribution of Weekly Sales (Log Scale)
2. Exploratory Data Analysis (EDA)
A comprehensive EDA was conducted to understand structure, patterns, seasonality, and correlations.
Analyses performed:
Weekly sales distribution
Store-level comparison
Department-level trends
Correlation heatmap
Holiday vs non-holiday
Seasonality by Month, Week, DayOfYear
Outliers & missing values
Correlation Heatmap
weekly_sales_outliers
store_size_vs_weekly_sales
holiday_vs_nonholiday
weekly_sales_over_time
avg_sales_by_store_type
Key Insights:
Sales show strong seasonal behavior, high variability between stores, and significant holiday effects.
3. Feature Engineering
Advanced feature engineering was applied to improve predictive power.
Added Features:
Date components: Month, Week, DayOfYear
Interaction features: Size × Dept
Log transformation: Log_Weekly_Sales
KMeans clustering: Cluster_ID + cluster distances
One-hot encoding
Holiday flags and calendar features
Actual vs Predicted
residual_plot
pca_cluster_visualization
Insight:
Engineered features improved the model's ability to capture store structure, seasonality, and complex interactions.
4. Baseline Model – Linear Regression
A simple Linear Regression model trained on the raw dataset.
Result:
High error and poor performance — appropriate as a baseline but insufficient for real prediction needs.
5. Improved Regression Models
With engineered features, three models were trained:
Model
MAE
RMSE
R²
Linear Regression (FE)
14511
21592
0.106
Gradient Boosting Regressor
5899
10184
0.801
Extra Trees Regressor (Winner)
2707
6517
0.919
Insight:
Extra Trees delivered the best performance, effectively capturing nonlinear patterns and complex interactions.
6. Regression Model Export
The winning regression model (Extra Trees Regressor) was exported as:
extra_trees_winner.pkl
and uploaded to this repository.
7. Regression → Classification Conversion
Weekly Sales were converted into binary classes using a median split:
Class 0 → Below median
Class 1 → Above median
The resulting classes were balanced, enabling stable classification training.
The class distribution after converting Weekly Sales into a binary target is shown below:
class_distribution
8. Classification Models
Three models were trained:
Model
Accuracy
Logistic Regression
0.587
Gradient Boosting Classifier
0.862
Random Forest Classifier (Winner)
0.884
Business Insight (FN > FP):
False Negatives (predicting low sales when actual sales are high) are far more costly due to stockouts and lost revenue.
Challenges & Fixes
Extra Trees initially caused long training times, so sampling was applied during tuning.