Skip to content

Repository files navigation

Sales Prediction ML Project (Beginner Friendly)

This project teaches a clean end-to-end machine learning workflow to predict SALES from transaction and product-related features using Linear Regression.

Business Goal

Predict SALES to understand how product, order, and market attributes influence revenue at transaction level.

What You Will Learn

  • 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

Project Structure

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

Dataset Placement

Place your cleaned dataset here:

  • sales_analysis_cleaned.xlsx in the parent folder:
  • c:\Project_WorkSpace\Sales Insights\sales_analysis_cleaned.xlsx

The script is already configured to read from that location.

Model Performance

Metric Value
R² Score 0.914
MAE 343.12
RMSE 612.85

Interpretation

  • 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.

Future Improvements

  • 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

Setup and Run

  1. Open terminal in:
    • c:\Project_WorkSpace\Sales Insights\sales_prediction_ml_project
  2. Install dependencies:
    • pip install -r requirements.txt
  3. Run training script:
    • python train_sales_prediction.py
  4. Run future sales prediction (uses saved model, no retraining):
    • python predict_future_sales.py

ML Workflow in This Script

  1. Load and inspect dataset
  2. Create model-friendly date features (OrderYear, OrderMonth, OrderDayOfWeek)
  3. Remove unnecessary identifier/contact columns
  4. Select meaningful predictive columns
  5. Build preprocessing pipeline:
    • Numeric: median imputation
    • Categorical: most-frequent imputation + one-hot encoding
  6. Split data (80% train, 20% test)
  7. Train LinearRegression
  8. Evaluate:
    • MAE: average absolute error
    • RMSE: penalizes larger errors
    • R2: explained variance score
  9. Generate visual diagnostics
  10. Save model + metrics

How to Explain Results to Stakeholders

Use this flow:

  1. "We built a baseline model to estimate sales per transaction."
  2. "Model quality is measured by MAE, RMSE, and R2."
  3. "Actual vs Predicted plot shows overall fit quality."
  4. "Residual plot shows where model under/over-predicts."
  5. "Coefficient analysis highlights strongest drivers of sales direction and magnitude."
  6. "This baseline can guide pricing, product mix, and forecasting discussions."

Beginner Notes

  • 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.

About

Machine Learning sales forecasting project using Linear Regression and future sales prediction with Python.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages