This project uses Machine Learning to predict future sales based on historical data. It implements a complete pipeline, including preprocessing, model training, and deployment via FastAPI.
sales-prediction-project/
│── data/ # Stores the dataset
│── models/ # Trained models
│── src/ # Main project code
│ ├── api/ # API code (FastAPI)
│ ├── ml/ # Model training code
│ ├── utils/ # Utility functions
│── tests/ # Unit tests
│── Makefile # Command automation
│── requirements.txt # Project dependencies
│── README.md # Documentation
- Python
- Pandas & Scikit-Learn
- MLflow (Experiment Tracking)
- FastAPI (Inference API)
- SOLID (Best practices in code architecture)
- Makefile (Task automation)
| Command | Description |
|---|---|
make init |
Sets up the virtual environment and installs dependencies. |
make train |
Downloads the dataset, trains the model, and saves logs. |
make backend |
Starts the FastAPI backend for predictions. |
make clean |
Removes temporary files and the virtual environment. |
make initThis will create a virtual environment and install all dependencies.
make trainWhat happens?
- Trains a regression model for sales forecasting.
- Saves the trained model in the
models/directory.
make backendThe API will be available at:
http://127.0.0.1:8000
You can test the API in Swagger UI:
http://127.0.0.1:8000/docs
To visualize the training experiments:
mlflow uiAccess it in your browser:
http://127.0.0.1:5000
If running on a remote machine:
mlflow ui --host 0.0.0.0 --port 5000Parameters:
| Field | Description |
|---|---|
1.705833e+09 |
Transaction timestamp |
0 |
Payment type (e.g., cash/card) |
12 |
Number of products in the cart |
4 |
Type of product purchased |
Endpoint: POST /predict
Example request using cURL:
curl -X 'POST' \
'http://127.0.0.1:8000/predict' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"features": [1.705833e+09, 0, 12, 4]
}'Input JSON:
{
"features": [1.705833e+09, 0, 12, 4]
}Example Response:
{
"prediction": 200.45
}