Time Series • Introduction to Time Series
Time Series / P1.10 Mini End-to-End Forecast

P1.10 Mini End-to-End Forecast

Practical 1 Introduction to Time Series

From a 24-month constructed sales series, complete a beginner workflow: inspect, clean, plot, split last 3 months as a check, forecast with a trailing mean, and interpret MAE.

Practical / Solution

P1.10 Mini End-to-End Forecast

Problem Statement

From a 24-month constructed sales series, complete a beginner workflow: inspect, clean, plot, split last 3 months as a check, forecast with a trailing mean, and interpret MAE.

Learning Outcomes

  • Run a full simple pipeline.
  • Hold out recent months for a check.
  • Report MAE without claiming a sophisticated model.

Hint

Do not use ARIMA. A trailing mean is enough for Unit 1.

Theory

An end-to-end beginner forecast still follows the process: understand the series, prepare it, choose a simple rule, check it on unused recent data, then interpret.

Dataset / Data Source

Constructed 24 monthly sales figures with a mild rise. Teaching data, not a Kaggle download.

Kaggle-style Workflow

  • Problem statement
  • Dataset description
  • Import libraries
  • Load and inspect
  • Clean
  • Exploratory plot
  • Simple model
  • Evaluate with MAE
  • Interpret and conclude

Analysis / Program

import pandas as pd import numpy as np import matplotlib.pyplot as plt idx = pd.date_range("2024-01-01", periods=24, freq="MS") sales = np.linspace(40, 70, 24) + np.array( [0, 1, -1, 2, 0, 3, -2, 1, 0, 2, -1, 4, 0, 1, -2, 2, 1, 0, 3, -1, 2, 0, 1, 2] ) ts = pd.Series(sales, index=idx, name="sales") print("Shape:", ts.shape) print("Missing:", ts.isna().sum()) print(ts.describe()) train, test = ts.iloc[:-3], ts.iloc[-3:] preds = pd.Series(train.tail(3).mean(), index=test.index) mae = (test - preds).abs().mean() print("Hold-out MAE:", round(mae, 2)) train.plot(label="train") test.plot(label="test") preds.plot(label="simple forecast", style="--") plt.legend() plt.title("Unit 1 mini forecast") plt.tight_layout() plt.show()

Expected Output

Printed shape, missing count, descriptive stats, a hold-out MAE, and a chart of train, test and a flat dashed forecast. MAE depends on this constructed series; do not quote it as a universal result.

Result / Interpretation

The pipeline shows inspection, a simple method and honest evaluation on later months. The forecast is crude, which is the educational point: process first, advanced models later.

Note

Evaluate a method on data not used to form the forecast whenever possible.