Dynamic Pricing System for ride-hailing applications, using Machine Learning and multiple real-world factors to optimize ride prices in real-time.
The system uses machine learning models to predict base prices based on ride characteristics and then applies dynamic (real-time) adjustments based on supply-demand, weather, time of day, user history, and many other factors.
Key Features:
- ✨ Smart Pricing: Base price prediction based on distance, time, vehicle type
- 🌦️ Real-time Factors: Price adjustments based on weather, traffic congestion, supply-demand
- 🚀 API Integration: RESTful API for real-world applications
- 📊 Analytics: Visual dashboard for analysis and simulation
Click to expand installation steps
- Clone repository:
git clone https://github.com/yourusername/dynamic-ride-pricing.git
cd dynamic-ride-pricing- Install libraries:
pip install -r requirements.txt- Train the model:
python main.py- Run API server:
python -m api.app- Run dashboard:
streamlit run dashboard/app.pyAPI runs at http://localhost:5001/api with the following endpoints:
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Check operational status |
/get-price |
POST | Calculate ride price based on parameters |
/simulate-rides |
GET | Simulate multiple rides with random parameters |
/pricing-factors |
GET | View factors affecting price |
The Streamlit dashboard provides:
-
Multiple Ride Simulation:
- 🚕 Create multiple random rides
- 📊 Analyze and visualize results
-
Parameter-based Simulation:
- 🎛️ Manually adjust ride parameters
- 🔍 View detailed pricing analysis
Click to expand project structure
dynamic-pricing/
│
├── api/ # API server module
│ ├── __init__.py
│ └── app.py # Flask API server
│
├── dashboard/ # Streamlit Dashboard
│ └── app.py # Dashboard application
│
├── data/ # Data processing module
│ ├── __init__.py
│ ├── data_generator.py # Sample data generator
│ └── preprocessor.py # Data preprocessing
│
├── models/ # ML model module
│ ├── __init__.py
│ └── pricing_model.py # Price prediction model
│
├── pricing/ # Dynamic Pricing module
│ ├── __init__.py
│ └── dynamic_pricer.py # Dynamic pricing algorithm
│
├── utils/ # Utilities
│ ├── __init__.py
│ └── geo_utils.py # Geographic/distance utilities
│
├── main.py # Main execution file
├── requirements.txt # Required libraries
└── README.md # This file
The system uses a 2-step process to determine prices:
Uses Random Forest model to predict price from distance, time, vehicle type. Result is the base price for the ride.
| Factor | Description | Impact |
|---|---|---|
| 🚗 Supply-Demand | Adjusts price based on driver availability and area demand | ±15% |
| 🌧️ Weather | Increases price during adverse weather conditions | +5-10% |
| 🚦 Congestion | Adjusts price according to traffic congestion levels | +3-12% |
| 🏆 Customer Loyalty | Discounts for loyal users | -5-15% |
Example results from the pricing system for a 5km ride:
- Base price: 75,000 VND
- Optimized price: 82,500 VND
- Price change %: +10.0%
Insights:
- Price increased by 10.0% compared to base price due to high demand during peak hours
- Area has low supply-demand ratio (8 drivers/45 requests)
- Weather conditions (rain) increased price by 5%
- 🐍 Python 3.9+
- 💾 4GB RAM (recommended)
- 💽 50MB disk space
Repository Setup Instructions
Place this README.md file in the root directory of the project (same level as main.py).
To add this file to the repository, do the following:
- Create a file named
README.mdin the root directory of the project - Copy the above content into the file
- Save the file and add it to the git repository:
git add README.md
git commit -m "Add project README"
git push
