Skip to content

πŸš– A hybrid Machine Learning + Reinforcement Learning project that predicts dynamic ride pricing. Combines historical ride data (ML) with a Q-learning agent (RL) to recommend fair, adaptive prices based on demand, supply, and customer loyalty.

Notifications You must be signed in to change notification settings

DivyanshGupta-16/Smart_Dynamic_Pricing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš– Smart Dynamic Pricing System

Python Streamlit

A hybrid Machine Learning + Reinforcement Learning system for dynamic ride pricing

Combining historical price estimation with Q-learning for adaptive pricing strategies

πŸš€ Quick Start β€’ πŸ“– Documentation β€’ 🎯 Features β€’ πŸ“Š Demo


🎯 Overview

This project implements an intelligent dynamic pricing system for ride-sharing services that combines:

  • πŸ“ˆ Machine Learning: Historical price estimation using median-based algorithms
  • πŸ€– Reinforcement Learning: Q-learning agent for optimal price multiplier selection
  • 🎨 Interactive Interface: Beautiful Streamlit web application for real-time predictions

The system adaptively adjusts ride prices based on demand, supply, vehicle type, and customer loyalty to maximize revenue while maintaining competitive pricing.

✨ Features

🧠 Intelligent Base Price Estimation

  • Hierarchical Fallback Strategy: Duration window β†’ Duration bins β†’ Vehicle type β†’ Global median
  • Robust Handling: Works with sparse data and missing historical records
  • Multi-tier Support: Economy, Premium, and Luxury vehicle pricing

🎯 Advanced Feature Engineering

  • Smart Bucketing: Demand (Low/Medium/High/Very High) and Supply (Low/Medium/High) levels
  • Loyalty Mapping: Vehicle type β†’ Customer tier (Regular/Silver/Gold)
  • State Representation: Optimized for reinforcement learning

πŸ€– Q-Learning Agent

  • Dynamic Environment: Simulates real ride scenarios as episodes
  • Price Multipliers: [0.8Γ—, 1.0Γ—, 1.2Γ—, 1.4Γ—] for flexible pricing
  • Reward Optimization: Revenue maximization with cost consideration
  • Epsilon-Greedy: Balanced exploration vs exploitation

🎨 Interactive Web Application

  • Real-time Predictions: Instant price recommendations
  • Auto-estimation: Optional historical price calculation
  • Visual Feedback: Clear metrics and state information
  • Responsive Design: Works on desktop and mobile

πŸš€ Live Demo

πŸ‘‰ Try the app here: Smart Dynamic Pricing App

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Installation

  1. Clone the repository

    git clone https://github.com/DivyanshGupta-16/Smart_Dynamic_Pricing.git
    cd dynamic-pricing-strategy
  2. Create virtual environment

    # Windows
    python -m venv venv
    venv\Scripts\activate
    
    # macOS/Linux
    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Run the application

    streamlit run app.py
  5. Open your browser to http://localhost:8501

πŸ“‚ Project Structure

dynamic-pricing-strategy/
β”œβ”€β”€ πŸ“ data/
β”‚   └── dynamic_pricing.csv          # Historical ride data
β”œβ”€β”€ πŸ“ src/
β”‚   β”œβ”€β”€ base_price.py               # Base price estimation logic
β”‚   β”œβ”€β”€ preprocessing.py            # Data preprocessing & state building
β”‚   β”œβ”€β”€ rl.py                       # RL environment & Q-learning agent
β”‚   └── utils.py                    # Feature engineering utilities
β”œβ”€β”€ πŸ“ assets/
β”‚   β”œβ”€β”€ base_price_1x.png          # Demo screenshots
β”‚   β”œβ”€β”€ base_price_1-2x.png
β”‚   β”œβ”€β”€ base_price_1-4x.png
β”‚   └── estimated_base_price.png
β”œβ”€β”€ app.py                          # Streamlit web application
β”œβ”€β”€ requirements.txt                # Python dependencies
└── README.md                       # This file

πŸ“Š Demo

πŸ–ΌοΈ Application Screenshots

Base Price Estimation
High Demand Scenario
Supply-Demand Imbalance
Duration-based Pricing

πŸ“ˆ Example Output

Base Price (ML Estimate): β‚Ή120.00
RL Multiplier: 1.20Γ—
State: ('High', 'Medium', 'Silver')
─────────────────────────────────
πŸ’° Final Recommended Price: β‚Ή144.00

🧠 Methodology

πŸ”„ Hybrid Approach

  1. Machine Learning Component

    • Analyzes historical ride data
    • Estimates base price using statistical methods
    • Handles missing data and edge cases
  2. Reinforcement Learning Component

    • Q-learning agent learns optimal pricing strategies
    • Considers demand, supply, and customer loyalty
    • Maximizes revenue through dynamic multiplier selection
  3. Integration

    • Final Price = Base Price Γ— RL Multiplier
    • Real-time adaptation to market conditions

πŸ“Š Data Requirements

Your dataset should include these columns:

Number_of_Riders,Number_of_Drivers,Vehicle_Type,Expected_Ride_Duration,Historical_Cost_of_Ride

πŸ› οΈ Usage

Web Interface

  1. Adjust sliders for demand (riders) and supply (drivers)
  2. Select vehicle type and expected duration
  3. Choose between manual input or auto-estimation for base price
  4. View real-time price recommendations

Programmatic Usage

from src.base_price import estimate_base_price
from src.rl import train_q_agent, DynamicPricingEnv
from src.preprocessing import load_data, preprocess

# Load and preprocess data
df = load_data("data/dynamic_pricing.csv")
processed_df = preprocess(df)

# Train RL agent
env = DynamicPricingEnv(processed_df)
agent = train_q_agent(env, episodes=25)

# Get price recommendation
base_price = estimate_base_price(df, "Premium", 30)
multiplier = agent.get_best_action(state)
final_price = base_price * multiplier

πŸ“‹ Dependencies

  • streamlit β‰₯ 1.33 - Web application framework
  • pandas β‰₯ 2.0 - Data manipulation and analysis
  • numpy β‰₯ 1.24 - Numerical computing

⭐ Star this repository if you found it helpful!

πŸ” Back to Top

About

πŸš– A hybrid Machine Learning + Reinforcement Learning project that predicts dynamic ride pricing. Combines historical ride data (ML) with a Q-learning agent (RL) to recommend fair, adaptive prices based on demand, supply, and customer loyalty.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages