Time Series / Sales Forecasting DS Market
- Home
- Project Details
Weekly Sales Forecasting Using XGBoost
Objective
This project focuses on building and training a time series forecasting model using XGBoost to predict weekly sales quantities for different items across various stores and regions. The ultimate goal is to provide accurate forecasts for the next four weeks, enabling data-driven decision-making for inventory and sales strategies.
Dataset Overview
Key features in the dataset include:
- Weekly Sales Quantities
- Average Prices
- Item Information
- Store and Region Details
- Product Categories
Prior to analysis, the data undergoes preprocessing to address missing values and convert categorical variables into numerical representations.
Methodology
1. Data Loading and Preprocessing
- Data types are converted for efficient processing.
- The dataset is filtered to include data from the last two years, ensuring recent and relevant trends are captured.
- Missing values are handled to maintain data integrity.
2. Feature Engineering
Advanced features are engineered to enhance model performance, including:
- Lagged Variables: Weekly quantities lagged for each item to capture temporal trends.
- Aggregated Sales Statistics:
- Metrics such as total, average, maximum, and minimum sales for various groupings (item, category, store, region).
3. Train-Test Split
The data is divided into:
- Training Set: Used for model training.
- Validation Set: Monitors performance during training to avoid overfitting.
- Testing Set: Evaluates the model’s predictive power.
4. Model Training
An XGBoost Regression Model is trained using the training set. Hyperparameters are tuned, and the validation set monitors performance.
5. Model Evaluation
Model performance is assessed using the Root Mean Squared Error (RMSE) metric, calculated for both the training and validation sets.
6. Prediction
- The trained model predicts weekly sales quantities for the test set and provides forecasts for the next four weeks.
- Predictions are saved in a structured format for further analysis:
submission_train_[rmse_train]_valida_[rmse_valida].csv.
Key Tools and Libraries
- pandas: For data manipulation and preprocessing.
- XGBoost: The core library for model training and predictions.
- scikit-learn: For train-test splits and evaluation metrics.
- matplotlib: To visualize feature importance and prediction results.
Evaluation Metrics
- Root Mean Squared Error (RMSE): Measures prediction accuracy, with lower values indicating better model performance.
Results
- The model achieves competitive RMSE scores on the training and validation datasets.
- Predictions for the test set and the next four weeks are saved for review.
- Visualizations include:
- Feature Importance: Highlights key drivers of the model’s predictions.
- Actual vs. Predicted Values: Offers insights into model accuracy and behavior.
Conclusion
This project demonstrates a robust approach to time series forecasting using XGBoost, combining:
- Comprehensive data preprocessing and feature engineering.
- Accurate model training and evaluation.
- Predictive insights for four-week forecasts, aiding operational and strategic planning.
By integrating detailed analysis and powerful machine learning techniques, this solution provides actionable predictions that can drive improved decision-making in sales and inventory management.