CoolFace
Apppublic

uzmiee/demand-forecasting-platform

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

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.

๐ŸŒŸ 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. 1.Clone the repository
bash
git clone https://github.com/uXmii/demand-forecasting-platform.git
cd demand-forecasting-platform
  1. 1.Create virtual environment
bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. 1.Install dependencies
bash
pip install -r requirements.txt
  1. 1.Run the application
bash
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. 1.Open the dashboard
  2. 2.Go to "Data Processing" tab
  3. 3.Leave file upload empty and click "Process Data"
  4. 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:

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

ModelMAPE (%)MAERMSERยฒ
Ensemble4.7812.316.80.952
XGBoost5.1213.117.20.948
LightGBM5.2413.417.50.945
ARIMA6.1515.219.10.932

๐Ÿงช Testing

Run the test suite:

bash
pytest tests/ -v

Run specific test categories:

bash
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

bash
python scripts/run_app.py

Production Deployment

Docker
bash
docker build -t demand-forecasting .
docker run -p 7860:7860 demand-forecasting
Hugging Face Spaces
  1. 1.Create a new Space on Hugging Face
  2. 2.Upload your code
  3. 3.Set runtime to Gradio
  4. 4.Deploy automatically
AWS/Cloud
bash
python scripts/deploy.py --platform aws

๐Ÿ“š API Usage

Training Models Programmatically

python
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

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

Development Setup

bash
# 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! โญ