Skip to content

AliHaiderBajwa/Sales-Forcast-Engine

Repository files navigation

📈 Sales Forecast Engine

Calculus-Based Time-Series Sales Predictor

Python scikit-learn Matplotlib Status

Applies linear regression, differentiation, and integration to a real monthly sales dataset (2019–2023) to predict future sales, analyze rates of change, and compute cumulative revenue - all in an interactive CLI.


📌 Overview

This project bridges pure calculus and applied machine learning by building a sales prediction pipeline on 60 months of real product sales data (Jan 2019 – Dec 2023).

Given the time-series dataset, the program:

  • Fits a linear regression model (S(t) = mt + b) to the sales trend
  • Applies differentiation (dS/dt) to measure the instantaneous rate of change of sales
  • Applies integration (∫S dt) to compute cumulative/total sales over any time window
  • Predicts sales for any future year entered by the user

✨ Features

Part 1 - Data Exploration & Visualization

  • Loads and summarizes sales_dataset.csv (60 monthly records, 2019–2023)
  • Prints dataset overview, missing-value check, and summary statistics
  • Line plot - sales trend over time
  • Histogram - sales frequency distribution

Part 2 - Predictive Model (Linear Regression)

  • Encodes each month as a sequential time index
  • Splits data 80/20 (train/test, no shuffle - respects time order)
  • Trains sklearn.LinearRegression and evaluates with MSE and
  • Predicts sales for any user-specified future year (e.g. 2025, 2050, 2100)

Part 3 - Derivative Analysis (Rate of Change)

  • Computes first-order finite differences (Sales.diff()) as the discrete derivative dS/dt
  • Applies a 3-month rolling average to smooth out noise
  • Plots raw rate of change vs. smoothed rate side-by-side

Part 4 - Integration (Cumulative Sales)

  • Uses the regression coefficients (m, b) to derive the antiderivative analytically:

    ∫(mt + b) dt = (m·t²)/2 + b·t

  • Computes total cumulative sales from t = 0 up to any time index

Interactive CLI Flow

Welcome screen (team info)
    ↓
Enter year for prediction
    ↓  [press any key]
Part 1: Data visualization
    ↓  [press any key]
Part 2: Model training + prediction
    ↓  [press any key]
Part 3: Derivative analysis
    ↓
Part 4: Cumulative sales + final summary
    ↓
Continue or terminate?

📂 Repository Structure

sales-forecast-engine/
├── python-pr.py          # Main interactive Python program
├── sales_dataset.csv     # Monthly sales dataset (Jan 2019 – Dec 2023, 60 records)
└── README.md

⚙️ Setup & Run

Prerequisites

pip install pandas numpy matplotlib scikit-learn

Run

python python-pr.py

When prompted, enter a year (e.g. 2025, 2050, or 2100) to get a future sales prediction. Follow the on-screen prompts to step through each part of the analysis.


🗃 Dataset

sales_dataset.csv - 60 monthly sales records:

Column Description
Date End-of-month date (DD/MM/YYYY)
Sales Monthly sales figure (USD)

Date range: January 2019 – December 2023
Sales range: ~$406 – $637 per month with a mild upward trend


📊 Sample Output

Predicted Sales for the year 2025: 574.83
Cumulative Sales up to December 2023: 31,204.17
Model R²: 0.87  |  MSE: 412.6

🧮 Calculus Applied

Concept Application
Linear Model S(t) = mt + b fitted to monthly sales
Differentiation dS/dt - rate of sales growth/decline per month
Integration ∫S(t) dt - total cumulative revenue over a period
Analytical Solution Closed-form antiderivative derived from regression coefficients

📄 License

Feel free to use or learn from this. Credit Appreciated but not required.

About

Python CLI that predicts future product sales using linear regression, differentiation (rate of change), and integration (cumulative revenue) on a 5-year monthly dataset. Calculus & ML applied together.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages