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
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.
- 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
- 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
- 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
- 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
π Try the app here: Smart Dynamic Pricing App
- Python 3.8 or higher
- pip package manager
-
Clone the repository
git clone https://github.com/DivyanshGupta-16/Smart_Dynamic_Pricing.git cd dynamic-pricing-strategy -
Create virtual environment
# Windows python -m venv venv venv\Scripts\activate # macOS/Linux python3 -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Run the application
streamlit run app.py
-
Open your browser to
http://localhost:8501
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
Base Price Estimation
|
High Demand Scenario
|
Supply-Demand Imbalance
|
Duration-based Pricing
|
Base Price (ML Estimate): βΉ120.00
RL Multiplier: 1.20Γ
State: ('High', 'Medium', 'Silver')
βββββββββββββββββββββββββββββββββ
π° Final Recommended Price: βΉ144.00
-
Machine Learning Component
- Analyzes historical ride data
- Estimates base price using statistical methods
- Handles missing data and edge cases
-
Reinforcement Learning Component
- Q-learning agent learns optimal pricing strategies
- Considers demand, supply, and customer loyalty
- Maximizes revenue through dynamic multiplier selection
-
Integration
- Final Price = Base Price Γ RL Multiplier
- Real-time adaptation to market conditions
Your dataset should include these columns:
Number_of_Riders,Number_of_Drivers,Vehicle_Type,Expected_Ride_Duration,Historical_Cost_of_Ride
- Adjust sliders for demand (riders) and supply (drivers)
- Select vehicle type and expected duration
- Choose between manual input or auto-estimation for base price
- View real-time price recommendations
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- 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!



