This project aims to forecast weekly sales for Walmart stores using machine learning techniques.
By analyzing historical sales data with store, department, and holiday information, we build models that predict future weekly sales with improved accuracy.
- Contains historical weekly sales records.
- Columns:
Store: Store numberDept: Department numberDate: Week dateIsHoliday: Whether the week contains a special holidayWeekly_Sales: Target variable (total sales for that week)
After preprocessing and feature engineering:
- Lag features:
lag_1,lag_2,lag_3,lag_4,lag_52 - Rolling mean features:
rolling_mean_4,rolling_mean_12 - Temporal features:
Year,Month,Week,Day - Holiday feature:
IsHoliday(encoded) - Scaled features using
MinMaxScaler
- Includes same features except
Weekly_Sales(to be predicted).
- Loaded train and test data.
- Converted
Datecolumn to datetime. - Sorted data by
Store,Dept,Date. - Merged datasets for consistent feature generation.
- Created lag and rolling mean features to capture past sales trends.
- Extracted time-based features (Month, Week, Year).
- Added historical sales behavior using lag & rolling averages.
- Scaled numerical features using MinMaxScaler.
- Split train dataset into:
- Train (70%)
- Validation (15%)
- Test (15%)
Trained multiple regression models to predict Weekly_Sales.
| Model | Description | Status |
|---|---|---|
| Linear Regression | Baseline model | ✅ |
| Random Forest Regressor | Ensemble tree-based model | ✅ |
| Decision Tree Regressor | Simple tree model | ✅ |
| Support Vector Machine (RBF) | Kernel-based regression | ✅ |
| XGBoost Regressor | Gradient boosting model | ✅ |
- R² Score
- Mean Absolute Error (MAE)
- Root Mean Squared Error (RMSE)
- Trained models on training data.
- Predicted on validation and test sets.
- Compared all models’ performance.
Shows how closely the model predictions align with actual sales trends over time.
All trained models and scaler were serialized using pickle for future predictions.
Since the test dataset lacks Weekly_Sales, lag and rolling features were generated using the combined train+test data.