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.
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
- 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
- Encodes each month as a sequential time index
- Splits data 80/20 (train/test, no shuffle - respects time order)
- Trains
sklearn.LinearRegressionand evaluates with MSE and R² - Predicts sales for any user-specified future year (e.g. 2025, 2050, 2100)
- 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
- 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
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?
sales-forecast-engine/
├── python-pr.py # Main interactive Python program
├── sales_dataset.csv # Monthly sales dataset (Jan 2019 – Dec 2023, 60 records)
└── README.md
pip install pandas numpy matplotlib scikit-learnpython python-pr.pyWhen 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.
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
Predicted Sales for the year 2025: 574.83
Cumulative Sales up to December 2023: 31,204.17
Model R²: 0.87 | MSE: 412.6
| 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 |
Feel free to use or learn from this. Credit Appreciated but not required.