This project teaches a clean end-to-end machine learning workflow to predict SALES from transaction and product-related features using Linear Regression.
Predict SALES to understand how product, order, and market attributes influence revenue at transaction level.
- How to load and inspect real business data with pandas
- How to prepare features for machine learning
- How to handle categorical encoding using one-hot encoding
- How to split train/test data using
train_test_split - How to train a baseline regression model with scikit-learn
- How to evaluate with MAE, RMSE, and R2
- How to visualize prediction quality and residual errors
- How to interpret linear model coefficients
- How to save a trained model with joblib
sales_prediction_ml_project/
|-- train_sales_prediction.py
|-- predict_future_sales.py
|-- inputs/
| |-- sample_future_orders.csv
|-- requirements.txt
|-- README.md
After running the script, this output structure is created:
sales_prediction_ml_project/
|-- outputs/
| |-- metrics.txt
| |-- feature_coefficients_full.csv
| |-- model/
| | |-- sales_linear_regression.joblib
| |-- plots/
| |-- actual_vs_predicted.png
| |-- residual_distribution.png
| |-- feature_coefficients.png
Place your cleaned dataset here:
sales_analysis_cleaned.xlsxin the parent folder:c:\Project_WorkSpace\Sales Insights\sales_analysis_cleaned.xlsx
The script is already configured to read from that location.
| Metric | Value |
|---|---|
| R² Score | 0.914 |
| MAE | 343.12 |
| RMSE | 612.85 |
- The model achieved strong prediction performance.
- Predicted sales values closely matched actual sales values.
- Residual analysis showed mostly centered error distribution.
- Feature coefficient analysis identified important business drivers.
- Implement Random Forest Regressor for better nonlinear prediction
- Compare multiple regression algorithms
- Deploy using Streamlit
- Create REST API for real-time prediction
- Integrate with Power BI dashboards
- Open terminal in:
c:\Project_WorkSpace\Sales Insights\sales_prediction_ml_project
- Install dependencies:
pip install -r requirements.txt
- Run training script:
python train_sales_prediction.py
- Run future sales prediction (uses saved model, no retraining):
python predict_future_sales.py
- Load and inspect dataset
- Create model-friendly date features (
OrderYear,OrderMonth,OrderDayOfWeek) - Remove unnecessary identifier/contact columns
- Select meaningful predictive columns
- Build preprocessing pipeline:
- Numeric: median imputation
- Categorical: most-frequent imputation + one-hot encoding
- Split data (
80% train,20% test) - Train
LinearRegression - Evaluate:
- MAE: average absolute error
- RMSE: penalizes larger errors
- R2: explained variance score
- Generate visual diagnostics
- Save model + metrics
Use this flow:
- "We built a baseline model to estimate sales per transaction."
- "Model quality is measured by MAE, RMSE, and R2."
- "Actual vs Predicted plot shows overall fit quality."
- "Residual plot shows where model under/over-predicts."
- "Coefficient analysis highlights strongest drivers of sales direction and magnitude."
- "This baseline can guide pricing, product mix, and forecasting discussions."
- This is a baseline model (simple and interpretable).
- High-cardinality fields are kept manageable through one-hot encoding.
- For future improvements, you can compare with tree-based models.
- Always validate with business logic, not only metrics.