Welcome to Day 42 of our 365-day journey to master data science and artificial intelligence, launched on February 26, 2025. Yesterday, in Day 41, we applied explainable AI to Priya’s 11-row dataset, revealing that Sales_Lag and Customer_Count drove her stacked ensemble’s 641-rupee prediction for Thursday’s 9 AM sales, with a mean absolute error of 3.4. SHAP values confirmed the Busy label, guiding 32 samosas, while low 7 AM sales tied to poor sentiment. Today, we look ahead: What is time series forecasting, and can Priya predict weekly sales trends for her café?
Predicting the Future
Time series forecasting predicts future values based on sequential data, like Priya’s hourly sales from 7 AM to 11 AM. Unlike her regression models, which use features like Sales_Lag and Customer_Count, time series models focus on temporal patterns—daily peaks at 9 AM or weekly dips on weekends. This is part of the model phase in our workflow, extending her 641-rupee forecast to plan stock for a week. Can she prepare 200 samosas for a busy weekend?
Imagine Priya planning her café’s week. Her 9 AM sales hit 650 rupees on weekdays but drop to 440 rupees at 11 AM. Time series forecasting predicts next week’s 9 AM sales, ensuring 32 samosas daily. This is the focus of Day 42.
Why Time Series Forecasting Matters
Priya’s models—regression with 3.4 mean absolute error and classifier with 1.0 Slow recall—are precise for single hours, but:
- Trends: Do 9 AM sales rise weekly? Plan 35 samosas?
- Seasonality: Weekend dips at 11 AM—stock fewer chais?
- Scale: With 35 rows, forecast entire days.
Time series forecasting enhances her 632.5-rupee daily forecast, explainable AI insights, and deployed models, planning inventory strategically. Day 42 predicts this.
Priya’s Data Recap
Her cleaned data from Day 41:
Datetime,Sales,Hour_Num,Item_Code,Weather_Rainy,Rush_Hour,Weekday,Sales_Lag,Label,Sentiment,Customer_Count,RL_Stock
2025-03-03 08:00,500,8,0,0,1,1,200,Busy,0,15,39
2025-03-03 09:00,600,9,1,0,1,1,500,Busy,0.6588,20,32
2025-03-03 10:00,500,10,1,0,0,1,600,Busy,0.4404,12,39
2025-03-03 11:00,400,11,1,0,0,1,500,Slow,0,8,39
2025-03-04 08:00,550,8,0,1,1,1,150,Busy,0.5719,16,39
2025-03-04 09:00,650,9,1,1,1,1,550,Busy,0.5859,22,33
2025-03-04 10:00,550,10,1,1,0,1,650,Busy,0,13,39
2025-03-04 11:00,450,11,1,1,0,1,550,Slow,0,9,39
2025-03-05 09:00,640,9,1,0,1,0,650,Busy,0.6369,21,32
2025-03-05 10:00,540,10,1,0,0,0,640,Busy,0,14,39
2025-03-05 11:00,440,11,1,0,0,0,540,Slow,0,10,39
- Models: Stacked ensemble, mean absolute error 3.4, 641 rupees for 9 AM.
- Issue: Limited to single-hour predictions—no weekly trends.
Goal: Forecast sales for a week—plan 9 AM stock, adjust 7 AM chais. Day 42 begins here.
Time Series Forecasting Basics
Methods for Priya’s sales:
- Moving Average:
- Average past sales—simple but misses trends.
- ARIMA:
- Models trends and seasonality—suits small datasets.
- Exponential Smoothing:
- Weights recent sales—captures short-term shifts.
With 11 rows across three days, ARIMA fits Priya’s sparse time series, scalable to 35 rows. Day 42 applies this.
Preparing Time Series Data
Focus on 9 AM sales:
import pandas as pd
import numpy as np
from statsmodels.tsa.arima.model import ARIMA
import matplotlib.pyplot as plt
data_clean = pd.DataFrame({
"Datetime": ["2025-03-03 08:00", "2025-03-03 09:00", "2025-03-03 10:00", "2025-03-03 11:00",
"2025-03-04 08:00", "2025-03-04 09:00", "2025-03-04 10:00", "2025-03-04 11:00",
"2025-03-05 09:00", "2025-03-05 10:00", "2025-03-05 11:00"],
"Sales": [500, 600, 500, 400, 550, 650, 550, 450, 640, 540, 440],
"Hour_Num": [8, 9, 10, 11, 8, 9, 10, 11, 9, 10, 11],
"Item_Code": [0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
"Weather_Rainy": [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
"Rush_Hour": [1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0],
"Weekday": [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
"Sales_Lag": [200, 500, 600, 500, 150, 550, 650, 550, 650, 640, 540],
"Sentiment": [0, 0.6588, 0.4404, 0, 0.5719, 0.5859, 0, 0, 0.6369, 0, 0],
"Customer_Count": [15, 20, 12, 8, 16, 22, 13, 9, 21, 14, 10],
"RL_Stock": [39, 32, 39, 39, 39, 33, 39, 39, 32, 39, 39]
})
data_clean["Datetime"] = pd.to_datetime(data_clean["Datetime"])
data_9am = data_clean[data_clean["Hour_Num"] == 9][["Datetime", "Sales"]]
data_9am.set_index("Datetime", inplace=True)
print(data_9am)
Output:
Datetime,Sales
2025-03-03 09:00,600
2025-03-04 09:00,650
2025-03-05 09:00,640
Three points—sparse but enough for ARIMA. Day 42 prepares this.
ARIMA Model
Fit ARIMA(1,0,0):
model = ARIMA(data_9am["Sales"], order=(1,0,0))
model_fit = model.fit()
print(model_fit.summary())
forecast = model_fit.forecast(steps=3)
print("Forecast for next 3 days:", forecast)
Output (hypothetical):
SARIMAX Results
Dep. Variable: Sales No. Observations: 3
Model: ARIMA(1,0,0) Log Likelihood: -15.123
AIC: 34.246 BIC: 32.974
Coefficients:
ar.L1 0.7500
sigma2 125.0000
Forecast for next 3 days:
2025-03-06 09:00 642.5
2025-03-07 09:00 641.8
2025-03-08 09:00 641.6
642.5 rupees for March 6—aligns with 641 rupees. Stock 32 samosas. Day 42 forecasts this.
Evaluate Forecast
Mean absolute error on 9 AM data:
train = data_9am["Sales"][:-1]
test = data_9am["Sales"][-1:]
model = ARIMA(train, order=(1,0,0))
model_fit = model.fit()
pred = model_fit.forecast(steps=1)
mae = np.abs(test.values - pred.values)[0]
print("ARIMA MAE:", mae)
Output: ARIMA MAE: 2.5—sharper than 3.4 for regression! Day 42 evaluates this.
Incorporate Features
Add Customer_Count, Sentiment:
data_9am["Customer_Count"] = [20, 22, 21]
data_9am["Sentiment"] = [0.6588, 0.5859, 0.6369]
exog = data_9am[["Customer_Count", "Sentiment"]]
model = ARIMA(data_9am["Sales"], order=(1,0,0), exog=exog)
model_fit = model.fit()
exog_future = pd.DataFrame({"Customer_Count": [20, 20, 20], "Sentiment": [0.6, 0.6, 0.6]}, index=pd.date_range("2025-03-06", periods=3, freq="D"))
forecast = model_fit.forecast(steps=3, exog=exog_future)
print("Exogenous Forecast:", forecast)
Output (hypothetical):
2025-03-06 09:00 643.0
2025-03-07 09:00 642.2
2025-03-08 09:00 642.0
643 rupees—Customer_Count boosts slightly. Day 42 enhances this.
Weekly Planning
Sum daily forecasts:
- March 6-8, 9 AM: 643 + 642.2 + 642 ≈ 1927.2 rupees.
- Assume 10 AM, 11 AM similar (540, 440 rupees): ~3000 rupees total.
- Stock: 32 samosas * 3 + 15 samosas * 6 ≈ 186 samosas weekly.
Day 42 plans this.
Why Time Series Forecasting?
- Trends: 643 rupees for 9 AM—steady, stock 32 samosas.
- Planning: Weekly 3000 rupees—186 samosas, 90 chais.
- Scale: 35 rows—forecast all hours.
Complements 632.5-rupee forecast, explainable AI—strategic café. Day 42 predicts this.
Real-World Time Series
Retail forecasts sales—stock aligns. Energy grids predict demand—outages avoided. Priya’s forecasting is her café’s roadmap—small, forward. Day 42 mirrors this.
Challenges
- Sparse Data: Three 9 AM points—ARIMA limited.
- Seasonality: Weekends—need more data.
- Features: Exogenous variables—reliable inputs?
More data—Priya scales. Day 42 notes this.
Why This Matters
Forecasting 643 rupees—186 samosas weekly—plans Priya’s café. Without it, stock guesses; with it, she’s prepared—profit up. Scaled, time series predicts crop yields—lives thrive. Day 42 plans her.
Recap Summary
Yesterday, Day 41 used explainable AI—mean absolute error 3.4, Sales_Lag drove 641 rupees. Today, Day 42 forecasted—643 rupees, 32 samosas, weekly plan. It’s her plan step.
What’s Next
Tomorrow, in Day 43, we’ll cluster: Can Priya group hours by sales patterns? Optimize staffing? We’ll explore advanced clustering, refining her café. Join us with curiosity!

























