Skip to content

MithraKL/dynamic-pricing-model

Repository files navigation

Dynamic Pricing Model & Optimizer Engine

OptimaPrice is an end-to-end Machine Learning-powered pricing engine that predicts and optimizes e-commerce product prices in real-time. By leveraging historical sales signals, competitor indices, and inventory levels, the system implements AI-driven pricing strategies responsive to fluctuating market demand.


🚀 Key Features

  • Three ML Model Architectures:
    • Ridge Regression: High-speed baseline model.
    • Random Forest Regressor: Ensembled decision tree for non-linear relations (highest accuracy).
    • PyTorch Multi-Layer Perceptron (MLP): Deep learning network capturing deep interactions.
  • Feature Engineering Pipeline: Extracts signals including competitor price differentials, price-to-cost margins, and inventory-to-demand availability ratios.
  • Flask REST API: Serves predictions (/api/predict), validation metrics (/api/metrics), and scenarios simulations (/api/simulate).
  • Glassmorphic Web UI: A beautiful dark-theme analytics dashboard showcasing real-time price optimization, sliders to adjust market features, and interactive Chart.js visualizations.
  • Docker Containerization: Portable container ready to deploy instantly.
  • AWS Ready: Pre-configured for deployment to AWS App Runner or AWS ECS Fargate.

📈 Model Performance Results

The models were evaluated using an 80/20 train-test split:

Model Architecture $R^2$ Score Mean Absolute Error (MAE) Training Time (sec)
Random Forest Regressor 0.9981 $2.87 3.28s
Neural Network (PyTorch) 0.9952 $5.02 50.28s
Ridge Regression 0.9925 $6.90 0.02s

🛠️ Project Structure

├── src/
│   ├── data_generator.py      # Synthetic dataset generator
│   └── train.py               # Preprocessing, feature engineering & model training
├── templates/
│   └── index.html             # Dashboard UI structure
├── static/
│   ├── css/
│   │   └── styles.css         # Glassmorphism dark-theme styling
│   └── js/
│       └── dashboard.js       # Live slider logic & Chart.js renderer
├── app.py                     # Flask API backend server
├── test_api.py                # Standard library automated API test client
├── Dockerfile                 # Multi-stage Docker image builder
├── docker-compose.yml         # Container compose runner
├── requirements.txt           # Python library dependencies
├── .gitignore                 # Excluded directories
└── AWS_DEPLOYMENT.md          # Guide for pushing to Amazon ECR/ECS/App Runner

💻 Local Setup & Installation

Prerequisites

  • Python 3.10+
  • Git

Installation

  1. Clone the Repository:

    git clone https://github.com/MithraKL/dynamic-pricing-model.git
    cd dynamic-pricing-model
  2. Create and Activate Virtual Environment:

    # Windows
    python -m venv venv
    .\venv\Scripts\Activate.ps1
    
    # Mac/Linux
    python3 -m venv venv
    source venv/bin/activate
  3. Install Dependencies:

    pip install -r requirements.txt
  4. Train Models: Generates synthetic dataset and exports preprocessors and model weights:

    python src/train.py

🖥️ Running the Application

Option A: Local Run

  1. Launch the Flask application:
    python app.py
  2. Open your browser and navigate to: 👉 http://127.0.0.1:5000

Option B: Docker Run

If you have Docker Desktop installed, run:

docker-compose up --build

The server will start listening at http://127.0.0.1:5000.


🧪 Running Automated Tests

To verify backend API endpoints (/api/predict, /api/metrics, /api/simulate) match validation criteria, run the test script while Flask is active:

python test_api.py

☁️ Cloud Deployment

For detailed configurations on how to push the Docker image to Amazon ECR and launch it on ECS Fargate or AWS App Runner, refer to the AWS_DEPLOYMENT.md file.


📝 License

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

About

An end-to-end Machine Learning dynamic pricing engine that predicts and optimizes e-commerce product prices in real-time using Ridge Regression, Random Forests, and PyTorch Neural Networks. Includes a responsive glassmorphic dark-mode dashboard and a Flask API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors