Dynamic Pricing is an essential aspect of modern business operations, where prices are dynamically adjusted based on various factors such as demand, seasonality, competition, and customer behavior. This project leverages machine learning to implement a robust Dynamic Pricing model, enabling businesses to optimize their pricing strategies effectively.
This project trains a machine learning model using a Gradient Boosting Regressor to predict optimal prices based on historical data. The model is managed and tracked with MLflow, which facilitates versioning, artifact storage, and model serving.
- Data Preprocessing: Handles input data preparation, including feature extraction and splitting into training and testing sets.
- Model Training: Utilizes a Gradient Boosting Regressor for accurate price prediction.
- Model Management: Tracks experiments, logs metrics, and registers models using MLflow.
- Dynamic Model Loading: Automatically fetches and loads the latest production model for predictions.
To run this project, ensure you have the following installed:
- Python 3.8+
- Required Python packages (listed in
requirements.txt
) - MLflow (for model tracking and management)
- Scikit-learn (for machine learning)
- Pandas (for data manipulation)
Install dependencies using:
pip install -r requirements.txt
Prepare two CSV files:
batch_test_data.csv
: test data for batch inference.single_test_data.csv
: test data for single inference.
Train and log the model using MLflow:
This script:
- Loads the data.
- Splits it into training and testing sets.
- Trains a Gradient Boosting Regressor.
- Logs the model and metrics (e.g., MAE) in MLflow.
Retrieve and use the model from its run:
model = mlflow.pyfunc.load_model((f"runs:/{run_id}/model")) #return run_id from train.py
predictions = model.predict(new_data)
If registered in the Model Registry:
model_uri = 'models:/dynamic_pricing_model/Production'
model = mlflow.pyfunc.load_model(model_uri)
predictions = model.predict(new_data)
Dynamic_Pricing/
|-- artifacts/
|-- scripts/
|-- __init__.py
|-- train.py # Script to train and log the model
|-- inference.py # Script for single and batch inference
|-- main.py # Script to run the pipeline
|-- preprocess.py # Script to preprocess
|-- requirements.txt # Dependencies for the project
|-- mlruns/ # MLflow tracking directory
|-- data/ # Sample input data
|-- README.md # Project documentation
To visualize and manage MLflow runs:
- Start the MLflow UI:
mlflow ui
- Navigate to http://localhost:5000.
- View logged runs, metrics, and artifacts.
This project is licensed under the MIT License. See LICENSE
for more details.
- Support for additional machine learning models.
- Integration with real-time pricing APIs.
- Enhanced data preprocessing pipelines.
- Deployment of the model for real-time inference.