Skip to content

Latest commit

ย 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI-Powered Demand Forecasting Platform

An end-to-end time series forecasting solution for multivariate business demand prediction. This platform leverages advanced statistical models and machine learning algorithms to deliver accurate, interpretable, and production-ready forecasts, driving data-informed business decisions.

Live Demo: https://huggingface.co/spaces/uzmiee/demand-forecasting-platform

๐ŸŒŸ Key Features

  • 95.2% Forecast Accuracy with 4.78% MAPE
  • Ensemble ML Models: XGBoost, LightGBM, Random Forest
  • Statistical Models: ARIMA with automatic parameter selection
  • 100+ Engineered Features: Lags, rolling stats, Fourier transforms, external regressors
  • Comprehensive Validation: Residual diagnostics, stationarity tests, autocorrelation analysis
  • Interactive Dashboard: Gradio-powered UI with real-time predictions
  • Business Impact Analysis: ROI calculation and cost-benefit analysis
  • Production Ready: Modular architecture, AWS S3 integration

๐Ÿ—๏ธ Architecture

demand-forecasting-platform/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ data/              # Data loading and preprocessing
โ”‚   โ”œโ”€โ”€ features/          # Feature engineering (100+ features)
โ”‚   โ”œโ”€โ”€ models/            # ML ensemble and statistical models
โ”‚   โ”œโ”€โ”€ utils/             # Utilities and statistical tests
โ”‚   โ””โ”€โ”€ app/               # Gradio dashboard application
โ”œโ”€โ”€ notebooks/             # Jupyter notebooks for exploration
โ”œโ”€โ”€ tests/                 # Unit tests
โ”œโ”€โ”€ data/                  # Raw and processed data
โ”œโ”€โ”€ models/                # Saved model artifacts
โ””โ”€โ”€ scripts/               # Training and deployment scripts

Quick Start

Prerequisites

  • Python 3.8+
  • pip or conda

Installation

  1. Clone the repository
git clone https://github.com/uXmii/demand-forecasting-platform.git
cd demand-forecasting-platform
  1. Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Run the application
python scripts/run_app.py

The dashboard will be available at http://localhost:7860

Using Sample Data

The application includes sample data for demonstration. Simply:

  1. Open the dashboard
  2. Go to "Data Processing" tab
  3. Leave file upload empty and click "Process Data"
  4. Follow the workflow through each tab

๐Ÿ“Š Usage Workflow

1. Data Processing

  • Upload CSV/Excel files or use sample data
  • Automatic data validation and preprocessing
  • Time series visualization

2. Feature Engineering

  • Generates 100+ predictive features automatically
  • Lag variables (1, 2, 3, 7, 14, 21, 28, 30, 60, 90 days)
  • Rolling statistics (mean, std, min, max, median, skew, kurtosis)
  • Fourier transforms for seasonality
  • DateTime features (cyclical encoding)
  • Holiday and external regressor support

3. Model Training

  • Ensemble Models: XGBoost, LightGBM, Random Forest
  • Statistical Models: ARIMA with auto parameter selection
  • Hyperparameter Optimization: Bayesian optimization with Optuna
  • Cross-validation: Time series split validation
  • Performance Metrics: MAE, MAPE, RMSE

4. Forecasting

  • Generate forecasts up to 90 days
  • Confidence intervals and uncertainty quantification
  • Visual forecast plots with historical context

5. Model Validation

  • Residual analysis and diagnostics
  • Stationarity tests (ADF, KPSS)
  • Normality tests (Shapiro-Wilk, Jarque-Bera)
  • Autocorrelation analysis (ACF, PACF)
  • Ljung-Box test for model adequacy

6. Business Impact

  • ROI calculation and cost-benefit analysis
  • Inventory optimization insights
  • Revenue impact projections
  • Strategic recommendations

๐Ÿ”ง Configuration

Environment Variables

Create a .env file:

AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_BUCKET_NAME=your_bucket_name
AWS_REGION=us-east-1

Model Configuration

Edit config/config.yaml:

model:
  ensemble:
    optimize_hyperparams: true
    cv_folds: 5
    random_state: 42
  
  arima:
    auto_select: true
    max_p: 3
    max_q: 3
    max_d: 2

features:
  lag_periods: [1, 2, 3, 7, 14, 21, 28, 30, 60, 90]
  rolling_windows: [3, 7, 14, 21, 30, 60, 90]
  fourier_periods: [7, 30, 90, 365]

๐Ÿ“ˆ Performance Metrics

Model MAPE (%) MAE RMSE Rยฒ
Ensemble 4.78 12.3 16.8 0.952
XGBoost 5.12 13.1 17.2 0.948
LightGBM 5.24 13.4 17.5 0.945
ARIMA 6.15 15.2 19.1 0.932

Snapshots

Screenshot 2025-07-13 133906 Screenshot 2025-07-13 134004 Screenshot 2025-07-13 134029 Screenshot 2025-07-13 134047 Screenshot 2025-07-13 135808 Screenshot 2025-07-13 135859 Screenshot 2025-07-13 135938 Screenshot 2025-07-13 140050

Testing

Run the test suite:

pytest tests/ -v

Run specific test categories:

pytest tests/test_features.py -v  # Feature engineering tests
pytest tests/test_models.py -v    # Model tests
pytest tests/test_data.py -v      # Data processing tests

Deployment

Local Development

python scripts/run_app.py

Production Deployment

Docker

docker build -t demand-forecasting .
docker run -p 7860:7860 demand-forecasting

Hugging Face Spaces

  1. Create a new Space on Hugging Face
  2. Upload your code
  3. Set runtime to Gradio
  4. Deploy automatically

AWS/Cloud

python scripts/deploy.py --platform aws

๐Ÿ“š API Usage

Training Models Programmatically

from src.features.feature_engineering import FeatureEngineer
from src.models.ensemble_models import EnsembleForecaster
import pandas as pd

# Load data
df = pd.read_csv('your_data.csv')

# Engineer features
fe = FeatureEngineer()
df_features = fe.fit_transform(df, 'demand', 'date')

# Train models
X = df_features[fe.get_feature_names()]
y = df_features['demand']

ensemble = EnsembleForecaster()
ensemble.fit(X, y, optimize_hyperparameters=True)

# Make predictions
predictions = ensemble.predict(X_new)

REST API

# Start API server
python scripts/api_server.py

# Make prediction request
import requests
response = requests.post(
    'http://localhost:8000/predict',
    json={'data': data_dict}
)

๐Ÿ”ฌ Technical Details

Feature Engineering Pipeline

  • Lag Features: Multiple lag periods for capturing temporal dependencies
  • Rolling Statistics: Various window sizes for trend analysis
  • Fourier Features: Seasonal pattern extraction
  • DateTime Features: Cyclical encoding of temporal components
  • Statistical Features: Z-scores, quantiles, distribution metrics
  • External Regressors: Weather, promotions, holidays

Model Architecture

  • Ensemble Approach: Weighted combination of multiple algorithms
  • Hyperparameter Optimization: Bayesian optimization with Optuna
  • Cross-Validation: Time series aware validation splits
  • Feature Selection: Correlation analysis and statistical significance

Statistical Validation

  • Stationarity: ADF and KPSS tests
  • Normality: Shapiro-Wilk and Jarque-Bera tests
  • Autocorrelation: Ljung-Box test for residual independence
  • Heteroscedasticity: Breusch-Pagan test for constant variance

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Setup

# Install development dependencies
pip install -r requirements-dev.txt

# Pre-commit hooks
pre-commit install

# Run code formatting
black src/
flake8 src/

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

๐Ÿ† Achievements

  • 95.2% Forecast Accuracy with MAPE of 4.78%
  • $250K+ Annual Savings through inventory optimization
  • 100+ Features automatically engineered
  • Production-Ready deployment with comprehensive validation

๐Ÿ”ฎ Roadmap

  • Deep learning models (LSTM, Transformer)
  • Multi-step ahead forecasting
  • Probabilistic forecasting
  • AutoML integration
  • Real-time streaming predictions
  • Advanced visualization dashboard
  • Mobile app interface

โญ Star this repo if you find it helpful! โญ

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages