A simple machine learning project to predict future sales totals based on product, customer, quantity, and price using a Random Forest Regressor. This project includes:
- Data preprocessing & model training
- Flask API for real-time predictions
- Visualization of prediction performance
- Easy setup & deployment-ready code
predict_sales_ai_model/
├── api/
│ ├── routes
| | └──__init__.py
| | └──v1.py
| ├── _init_.py
| └── app.py
├── charts/
│ └── random_forest_prediction_vs_actual.png
├── data/
│ └── sales_50.csv
│ └── sales_1000.csv
├── model/
│ └──random_forest
| ├── model.pkl
| ├── model_columns.pkl
| └── train_and_save.py
├── tests/
│ └── test_random_forest_model.py (optional)
├── requirements.txt
├── .gitignore
└── README.md
product: Product name (categorical)customer: Customer name (categorical)quantity: Number of units soldprice: Price per unit
total = quantity × price is used as the prediction target.
-
Algorithm: Random Forest Regressor
-
Framework: scikit-learn
-
Evaluation:
- Mean Absolute Error: ~19.82 AED
- R² Score: 1.0 (excellent fit)
# Activate your virtual environment
python -m venv venv
venv\Scripts\activate # On Windows
# Install dependencies
python -m pip install -r requirements.txt
# Train and save the model
python -m model.random_forest.train_and_save# Test the model
python -m tests.test_random_forest_model
python -m api.appThe API will start at: http://127.0.0.1:5000/
curl -X POST http://127.0.0.1:5000/api/v1/predict -H "Content-Type: application/json" -d "{\"product\": \"Laptop\", \"customer\": \"John\", \"quantity\": 2, \"price\": 800}"Response:
{
"predicted_total": 1520.0
}This chart compares actual and predicted sales totals on the test set.
Flask
pandas
scikit-learn
joblib
matplotlib
__pycache__/
*.pkl
.env
venv/
*.pyc
.DS_Store
MIT License
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Shahzad Software Engineer | ML Enthusiast
For any questions or suggestions, feel free to reach out!
