65. How to Forecast Sales with Time Series in Python (pandas and sklearn)
65.8 Practice, Tip and Close
Why. You need one lab that ties baselines, lags, time split and scores — plus a short note on statsmodels.
What. Optional Holt-Winters (ExponentialSmoothing) adds trend + season in one classical model. ARIMA is another classical family (needs care with differencing). Install: python -m pip install statsmodels.
How — optional Holt-Winters (we ran this).
from statsmodels.tsa.holtwinters import ExponentialSmoothing
import pandas as pd
df = pd.read_csv("mauli_monthly_sales.csv", parse_dates=["month"]).sort_values("month")
train = df.iloc[:30].set_index("month")["sales_inr"].astype(float)
hw = ExponentialSmoothing(train, trend="add", seasonal="add", seasonal_periods=12).fit(optimized=True)
print(hw.forecast(6).round(0).astype(int).tolist())
Output you should see.
[654393, 627037, 615868, 684434, 774918, 827087]
What it means. HW MAE ≈ ₹21,162 (MAPE ≈ 2.79%) on this lab — better than naive, behind our lag+LR. Use it when you want a classical seasonal baseline.
Chapter practice lab
- Load
mauli_monthly_sales.csv(36 monthly rows:month,sales_inr). - Split at 2026-05-01 (train 30 / test 6).
- Build naive, seasonal naive, MA3, and lag1+lag12+t LinearRegression.
- Print a MAE/MAPE scoreboard.
- Plot actual vs best forecast; save
outputs/ch55_forecast.png. - Write three WhatsApp lines for Priya: best model name, MAE in ₹, MAPE %.
Practice task
Amir (Austin bank): build MA3 on new_deposits_usd and a naive next-month guess. No shuffle. Report both numbers in $.
Ravindra Bagale's Tip
Baselines → lags → time split → MAE/MAPE → plot. This order keeps interviews clear. Got it?
Ravindra Bagale's Tip – मराठी
Baselines → lags → time split → MAE/MAPE → plot. या क्रमाने interview clear होते. समजला का?
Ravindra Bagale's Tip – हिंदी
Baselines → lags → time split → MAE/MAPE → plot। इस क्रम से interview साफ़ रहता है। समझे?
Thodkyaat sangaycha tar (quick recap)
- Forecast = next values from past values in time order
- Naive and seasonal naive are required baselines
- Moving average smooths noise but stays flat if you freeze it
- Lag features + LinearRegression reuse sklearn skills on months
- Never shuffle a forecasting split
- MAE (₹) and MAPE (%) decide the winner
- statsmodels Holt-Winters / ARIMA are optional classical tools