Skip to content

From study to forecast in the Series lab

Bring the track together in the Series lab. Look at a series, test what you need, and carry differences, season and training window into a forecast experiment with your eyes open.

Applied ~12 min9 steps

What runs in CodeSplash

You will be able to

  • Walk the Series lab's steps, and say what each one is for
  • Read where each hand-off suggestion comes from, and when to override it
  • Start a forecast experiment from a study, and judge the result by its backtest

Read first

01

One study, in order

Read

Each lesson in this track answered one question. The Series lab puts them in a working order, for one series:

Series → Look → Stationarity → Dependence → Trend → Breaks → Relationships → Cointegration → VAR → Panel → Forecast

Each middle step runs one method and saves it as an ordinary analysis. You can skip the ones that don't apply. Panel needs a unit key, for example, and Cointegration needs another series.

Get there from Series lab in Forecast's rail, or from Open in Series lab on an Insights finding about a trend, a season, non-stationarity or a level shift.

02

Start with a look

In the app

Take monthly airline passengers. Look runs a decomposition:

Seasonal decompositionRecorded · Python and R agreeRecorded 2026-11-17 · 7 values compared
R

F_T = 0.99, F_S = 0.93

Trend strength
0.9927
Seasonal strength
0.9337
Season length
12

Plots

Classical (multiplicative) decomposition of passengersHow much of the series is trend, how much a repeating season, and what is left?
View data
passengersremainderseasonaltrendmonth
112—0.9102—−662,688,000,000
118—0.8836—−660,009,600,000
132—1.007—−657,590,400,000
129—0.9759—−654,912,000,000
121—0.9814—−652,320,000,000
135—1.113—−649,641,600,000
1480.95171.227126.79−647,049,600,000
1480.95341.220127.25−644,371,200,000
1361.0021.060127.96−641,692,800,000
1191.0040.9218128.58−639,100,800,000
1041.0060.8012129−636,422,400,000
1181.0120.8988129.75−633,830,400,000
1150.96260.9102131.25−631,152,000,000
1261.0710.8836133.08−628,473,600,000
1411.0371.007134.92−626,054,400,000
1351.0140.9759136.42−623,376,000,000
1250.92690.9814137.42−620,784,000,000
1490.96501.113138.75−618,105,600,000
1700.98361.227140.92−615,513,600,000
1700.97341.220143.17−612,835,200,000
1581.0231.060145.71−610,156,800,000
1330.97220.9218148.42−607,564,800,000
1140.93900.8012151.54−604,886,400,000
1401.0070.8988154.71−602,294,400,000
1451.0140.9102157.13−599,616,000,000
1501.0640.8836159.54−596,937,600,000
1781.0921.007161.83−594,518,400,000
1631.0180.9759164.13−591,840,000,000
1721.0520.9814166.67−589,248,000,000
1780.94601.113169.08−586,569,600,000
1990.94741.227171.25−583,977,600,000
1990.93981.220173.58−581,299,200,000
1840.98891.060175.46−578,620,800,000
1620.99390.9218176.83−576,028,800,000
1461.0240.8012178.04−573,350,400,000
1661.0250.8988180.17−570,758,400,000
1711.0260.9102183.13−568,080,000,000
1801.0940.8836186.21−565,401,600,000
1931.0131.007189.04−562,896,000,000
1810.96960.9759191.29−560,217,600,000
1830.96330.9814193.58−557,625,600,000
2181.0001.113195.83−554,947,200,000
2300.94691.227198.04−552,355,200,000
2420.99311.220199.75−549,676,800,000
2090.97461.060202.21−546,998,400,000
1911.0050.9218206.25−544,406,400,000
1721.0200.8012210.42−541,728,000,000
1941.0120.8988213.38−539,136,000,000
1960.99770.9102215.83−536,457,600,000
1961.0150.8836218.50−533,779,200,000
2361.0601.007220.92−531,360,000,000
2351.0800.9759222.92−528,681,600,000
2291.0410.9814224.08−526,089,600,000
2430.97181.113224.71−523,411,200,000
2640.95521.227225.33−520,819,200,000
2720.98951.220225.33−518,140,800,000
2370.99341.060224.96−515,462,400,000
2111.0190.9218224.58−512,870,400,000
1801.0010.8012224.46−510,192,000,000
2010.99150.8988225.54−507,600,000,000

First 60 of 144 rows.

Periodogram of passengersWhich cycle lengths carry the most variation in the series?
View data
passengers
112
118
132
129
121
135
148
148
136
119
104
118
115
126
141
135
125
149
170
170
158
133
114
140
145
150
178
163
172
178
199
199
184
162
146
166
171
180
193
181
183
218
230
242
209
191
172
194
196
196
236
235
229
243
264
272
237
211
180
201

First 60 of 144 rows.

Strength of each component

ComponentStrength (0–1)
Trend0.9927
Seasonal0.9337
  • Strength = max(0, 1 − Var(remainder) / Var(component + remainder)) (Wang, Smith & Hyndman 2006); computed on logs for multiplicative seasonality.
  • The classical trend is missing for half a cycle at each end.
The exact R script · R R version 4.5.1 (2025-06-13)
# Seasonal decomposition
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method ts.decompose 1.0.1 · spec 5c47ac8993ca8807
# Dataset: ml_airpassengers (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ml_airpassengers.parquet", col_select = c("passengers", "month")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("passengers", "month")]), , drop = FALSE]  # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
  warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("passengers", "month"))  # infinite values stop the run (registry/errors.yaml)

# %% Series
VALUE <- "passengers"
TIME <- "month"
TEMPORAL <- TRUE
METHOD <- "classical"
PERIOD <- NULL
PERIODS <- as.integer(c(24, 168))
SWIN <- NULL
KIND <- "multiplicative"
s <- cs_ts_ordered(df, VALUE, TIME, TEMPORAL)
x <- s$x
labels <- s$labels
n <- length(x)
if (s$dups > 0) warnings <- c(warnings, sprintf("%d repeated time values: the decomposition assumes evenly spaced observations.", s$dups))
# A decomposition needs two full cycles of a season at least 2 long (5 observations) and a series that varies;
# short or constant series stop with a catalog message (registry/errors.yaml), the same in Python.
cs_check_rows(n, 5, "A seasonal decomposition")
if (METHOD == "mstl") {
  periods <- sort(PERIODS[PERIODS >= 2 & PERIODS < n / 2])
  if (!length(periods)) {
    if (any(PERIODS >= 2)) cs_check_rows(n, 2 * min(PERIODS[PERIODS >= 2]) + 1, "A seasonal decomposition")
    stop("MSTL needs at least one seasonal period shorter than half the series.")
  }
  period <- periods[1]
} else {
  period <- if (!is.null(PERIOD)) as.integer(PERIOD) else if (!is.null(TIME)) cs_ts_guess_period(s$df[[TIME]], TEMPORAL) else NULL
  if (is.null(period)) stop("Set the season length: it could not be read from the time column.")
  cs_check_rows(n, 2 * period + 1, "A seasonal decomposition")  # two full cycles
}
cs_check_not_constant(x, VALUE)

# %% Decompose
values <- list(n_obs = n, method = METHOD, period = period)
if (METHOD == "stl") {
  d <- cs_ts_stl(x, period, if (is.null(SWIN)) "periodic" else as.integer(SWIN))
  seasonal <- d$seasonal
} else if (METHOD == "classical") {
  d <- cs_ts_classical_decompose(x, period, KIND)
  seasonal <- d$seasonal
  values$seasonal_range <- max(d$figure) - min(d$figure)
} else {
  d <- cs_ts_mstl(x, periods)
  seasonal <- Reduce(`+`, d$seasonals)
  for (p in names(d$seasonals)) values[[paste0("seasonal_strength_", p)]] <- cs_ts_seasonal_strength(d$seasonals[[p]], d$remainder)
}
trend <- d$trend
rem <- d$remainder
ok <- !is.na(rem)
if (METHOD == "classical" && KIND == "multiplicative") {
  tr_s <- log(trend[ok]); se_s <- log(seasonal[ok]); re_s <- log(rem[ok])
} else {
  tr_s <- trend[ok]; se_s <- seasonal[ok]; re_s <- rem[ok]
}
values$seasonal_strength <- cs_ts_seasonal_strength(se_s, re_s)
values$trend_strength <- cs_ts_trend_strength(tr_s, re_s)
values$remainder_sd <- stats::sd(re_s)
name <- switch(METHOD, stl = "STL", mstl = "MSTL", classical = sprintf("Classical (%s)", KIND))
summary <- paste0(sprintf("%s decomposition of %s (%d observations, season length %d", name, VALUE, n, period),
                  if (METHOD == "mstl") sprintf("; periods %s", paste(periods, collapse = ", ")) else "",
                  sprintf("): trend strength %.2f, seasonal strength %.2f (0 = none, 1 = all of the variation).", values$trend_strength, values$seasonal_strength))
rows <- list(list(component = "Trend", strength = values$trend_strength),
             list(component = paste0("Seasonal", if (METHOD == "mstl") " (all periods)" else ""), strength = values$seasonal_strength))
if (METHOD == "mstl") for (p in periods) rows[[length(rows) + 1]] <- list(component = sprintf("Seasonal, period %d", p), strength = values[[paste0("seasonal_strength_", p)]])
kind <- if (TEMPORAL) "temporal" else "numeric"
na_null <- function(a) lapply(a, function(v) if (is.na(v)) NULL else v)
cs_publish(list(
  method = "ts.decompose",
  methodVersion = "1.0.1",
  title = "Seasonal decomposition",
  engine = cs_engine_info("stats", "nanoparquet"),
  n = n,
  summary = summary,
  apa = sprintf("F_T = %.2f, F_S = %.2f", values$trend_strength, values$seasonal_strength),
  statistics = list(list(key = "trend_strength", label = "Trend strength", value = values$trend_strength),
                    list(key = "seasonal_strength", label = "Seasonal strength", value = values$seasonal_strength),
                    list(key = "period", label = "Season length", value = period)),
  tables = list(list(key = "strength", title = "Strength of each component",
                     columns = list(list(key = "component", label = "Component", type = "string"), list(key = "strength", label = "Strength (0–1)", type = "number")),
                     rows = rows)),
  effectSizes = list(),
  assumptions = list(),
  warnings = warnings,
  notes = list(paste0("Strength = max(0, 1 − Var(remainder) / Var(component + remainder)) (Wang, Smith & Hyndman 2006)",
                      if (KIND == "multiplicative" && METHOD == "classical") "; computed on logs for multiplicative seasonality." else "."),
               switch(METHOD, stl = "A periodic seasonal window fixes one seasonal pattern; a finite window lets it drift.",
                      classical = "The classical trend is missing for half a cycle at each end.",
                      "MSTL removes the shortest cycle first, then the longer ones, twice over.")),
  charts = list(
    cs_chart("decomposition", "stl-decomposition", sprintf("%s decomposition of %s", name, VALUE), list(
      x = cs_col(if (is.null(TIME)) "index" else TIME, labels, kind = kind), observed = cs_col(VALUE, x),
      trend = cs_col("trend", na_null(trend), kind = "numeric"), seasonal = cs_col("seasonal", na_null(seasonal), kind = "numeric"),
      remainder = cs_col("remainder", na_null(rem), kind = "numeric")),
      controls = list(multiplicative = METHOD == "classical" && KIND == "multiplicative")),
    cs_chart("periodogram", "periodogram", sprintf("Periodogram of %s", VALUE), list(y = cs_col(VALUE, x)), controls = list(period = period))),
  values = values
))
Python

F_T = 0.99, F_S = 0.93

Trend strength
0.9927
Seasonal strength
0.9337
Season length
12

To keep this page light, the plots are shown once, under the R tab.

Strength of each component

ComponentStrength (0–1)
Trend0.9927
Seasonal0.9337
  • Strength = max(0, 1 − Var(remainder) / Var(component + remainder)) (Wang, Smith & Hyndman 2006); computed on logs for multiplicative seasonality.
  • The classical trend is missing for half a cycle at each end.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Seasonal decomposition
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method ts.decompose 1.0.1 · spec 5c47ac8993ca8807
# Dataset: ml_airpassengers (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import numpy as np
import pandas as pd

import codesplash as cs
from codesplash.errors import check_not_constant
from codesplash.stats import ts

# %% Data
df = pd.read_parquet("tests/parity/fixtures/ml_airpassengers.parquet", columns=["passengers", "month"])
n_input = len(df)
df = df.dropna(subset=["passengers", "month"])  # listwise deletion over the analysis columns
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
    warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
    cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["passengers", "month"])  # infinite values stop the run (registry/errors.yaml)

# %% Series
VALUE = "passengers"
TIME = "month"
TEMPORAL = True
METHOD = "classical"
PERIOD = None
PERIODS = [int(v) for v in [24, 168]]
SWIN = None
KIND = "multiplicative"
s = ts.ordered(df, VALUE, TIME, TEMPORAL)
x, labels = s["x"], s["labels"]
n = len(x)
if s["dups"]:
    warnings.append(f"{s['dups']} repeated time values: the decomposition assumes evenly spaced observations.")
# A decomposition needs two full cycles of a season at least 2 long (5 observations) and a series that varies;
# short or constant series stop with a catalog message (registry/errors.yaml), the same in R.
cs.check_rows(n, 5, "A seasonal decomposition")
if METHOD == "mstl":
    periods = sorted(p for p in PERIODS if 2 <= p < n / 2)
    if not periods:
        if any(p >= 2 for p in PERIODS):
            cs.check_rows(n, 2 * min(p for p in PERIODS if p >= 2) + 1, "A seasonal decomposition")
        raise ValueError("MSTL needs at least one seasonal period shorter than half the series.")
    period = periods[0]
else:
    period = int(PERIOD) if PERIOD is not None else ts.guess_period(s["df"][TIME].to_numpy(), TEMPORAL) if TIME else None
    if period is None:
        raise ValueError("Set the season length: it could not be read from the time column.")
    cs.check_rows(n, 2 * period + 1, "A seasonal decomposition")  # two full cycles
check_not_constant(x, VALUE)

# %% Decompose
values = {"n_obs": n, "method": METHOD, "period": period}
if METHOD == "stl":
    d = ts.stl(x, period, "periodic" if SWIN is None else int(SWIN))
    seasonal = d["seasonal"]
elif METHOD == "classical":
    d = ts.classical_decompose(x, period, KIND)
    seasonal = d["seasonal"]
    values["seasonal_range"] = float(np.max(d["figure"]) - np.min(d["figure"]))
else:
    d = ts.mstl(x, periods)
    seasonal = sum(d["seasonals"].values())
    for p, sp in d["seasonals"].items():
        values[f"seasonal_strength_{p}"] = ts.seasonal_strength(sp, d["remainder"])
trend, rem = d["trend"], d["remainder"]
ok = ~np.isnan(rem)
if METHOD == "classical" and KIND == "multiplicative":
    tr_s, se_s, re_s = np.log(trend[ok]), np.log(seasonal[ok]), np.log(rem[ok])
else:
    tr_s, se_s, re_s = trend[ok], seasonal[ok], rem[ok]
values.update({"seasonal_strength": ts.seasonal_strength(se_s, re_s), "trend_strength": ts.trend_strength(tr_s, re_s),
               "remainder_sd": float(np.std(re_s, ddof=1))})
name = {"stl": "STL", "mstl": "MSTL", "classical": f"Classical ({KIND})"}[METHOD]
summary = (f"{name} decomposition of {VALUE} ({n} observations, season length {period}"
           + (f"; periods {', '.join(str(p) for p in periods)}" if METHOD == "mstl" else "")
           + f"): trend strength {values['trend_strength']:.2f}, seasonal strength {values['seasonal_strength']:.2f} (0 = none, 1 = all of the variation).")
rows = [{"component": "Trend", "strength": values["trend_strength"]}, {"component": "Seasonal" + (" (all periods)" if METHOD == "mstl" else ""), "strength": values["seasonal_strength"]}]
if METHOD == "mstl":
    rows += [{"component": f"Seasonal, period {p}", "strength": values[f"seasonal_strength_{p}"]} for p in periods]
kind = "temporal" if TEMPORAL else "numeric"
nan_none = lambda a: [None if np.isnan(v) else float(v) for v in a]
cs.publish({
    "method": "ts.decompose",
    "methodVersion": "1.0.1",
    "title": "Seasonal decomposition",
    "engine": cs.engine_info("pandas", "numpy", "statsmodels"),
    "n": n,
    "summary": summary,
    "apa": f"F_T = {values['trend_strength']:.2f}, F_S = {values['seasonal_strength']:.2f}",
    "statistics": [{"key": "trend_strength", "label": "Trend strength", "value": values["trend_strength"]},
                   {"key": "seasonal_strength", "label": "Seasonal strength", "value": values["seasonal_strength"]},
                   {"key": "period", "label": "Season length", "value": period}],
    "tables": [{"key": "strength", "title": "Strength of each component",
                "columns": [{"key": "component", "label": "Component", "type": "string"}, {"key": "strength", "label": "Strength (0–1)", "type": "number"}],
                "rows": rows}],
    "effectSizes": [],
    "assumptions": [],
    "warnings": warnings,
    "notes": ["Strength = max(0, 1 − Var(remainder) / Var(component + remainder)) (Wang, Smith & Hyndman 2006)" + ("; computed on logs for multiplicative seasonality." if KIND == "multiplicative" and METHOD == "classical" else "."),
              "A periodic seasonal window fixes one seasonal pattern; a finite window lets it drift." if METHOD == "stl" else "The classical trend is missing for half a cycle at each end." if METHOD == "classical" else "MSTL removes the shortest cycle first, then the longer ones, twice over."],
    "charts": [cs.chart("decomposition", "stl-decomposition", f"{name} decomposition of {VALUE}", {
                   "x": cs.col(TIME or "index", labels, kind=kind), "observed": cs.col(VALUE, x), "trend": cs.col("trend", nan_none(trend), kind="numeric"),
                   "seasonal": cs.col("seasonal", nan_none(seasonal), kind="numeric"), "remainder": cs.col("remainder", nan_none(rem), kind="numeric")},
                   controls={"multiplicative": METHOD == "classical" and KIND == "multiplicative"}),
               cs.chart("periodogram", "periodogram", f"Periodogram of {VALUE}", {"y": cs.col(VALUE, x)}, controls={"period": period})],
    "values": values,
})

Seasonal strength is 0.93 and trend strength is 0.99.

Before you run anything else, write down what you expect the stationarity step to say, and what you'd do about the season.

03

What does the lab suggest?

Predict

Predict first

The Forecast step reads your results. Stationarity recommends 2 differences. Look found strong seasonality, above the threshold the ARIMA search uses for one seasonal difference.

What will the hand-off suggest?

d = 1, D = 1d = 2, D = 1d = 0, D = 0
Reveal

dd = 2 and DD = 1, with each reason stated next to it. The battery doesn't know about the season, though. Two ordinary differences and a seasonal one is a lot, and the classic model for this series, ARIMA(0,1,1)(0,1,1)[12], uses dd = 1. Every suggestion stays editable, so change it, and let a backtest decide.

04

Where the training window comes from

Predict

Predict first

Breaks finds that the Nile's level shifts around 1898, from a mean of 1,098 to 850. Should a forecast of future flows train on all the years?

Yes: use all the data you haveNo: start after the shift, if enough data remainOnly if you remove the outliers
Reveal

Training across a break mixes two regimes, so start after it, as long as enough data remain. The hand-off sets Train from to the last change, and it keeps all the data, with a note, if the remaining part would be too short to fit and backtest. PELT gives 1 change on this series.

05

Read the hand-off

Reflect

From this study to a forecast lists the values with their reasons:

FieldComes from
Differences dThe unit-root battery
Seasonal differences DSeasonal strength from Look
Season lengthThe decomposition's period
Train fromThe last change in Breaks

A step you skipped leaves its value empty, and the forecast chooses for itself. Which of these would you be least willing to accept without looking?

06

Tests inform, backtests decide

Read

These steps give you hypotheses about the series. None of them shows that a forecast will work:

  • A clean Dependence step says that a pattern isn't obvious, not that nothing can be predicted.
  • A significant Relationships result says a series helps predict another. It only helps if you'll know its future. See the ARIMAX lesson for that catch.
  • A VAR step's impulse responses depend on the order of the series.

Use Start a forecast experiment to test these ideas on the same origins, or Open one ARIMA forecast for a quick look.

07

Run the experiment

In the app

The experiment opens with your choices filled in. Add baselines to Models, even if you feel sure about the others. Then check Leaderboard and Compare, as the walkthrough does for {{value}}.

If seasonal naive comes close to your tuned model, what will you ship? Try it on your own data, or on the practice data in the tour.

08

Check your understanding

Checkpoint

Check yourself

Put these in a sensible working order for a new series.

  1. 1Look for breaks
  2. 2Compare models on the same origins
  3. 3Look at the decomposition
  4. 4Test stationarity
  5. 5Start a forecast experiment with baselines

Show the answer

The order:

  1. Look at the decomposition
  2. Test stationarity
  3. Look for breaks
  4. Start a forecast experiment with baselines
  5. Compare models on the same origins

Look first. The tests shape the model choices, and the backtest makes the decision.

Check yourself

The hand-off suggests dd = 2 and DD = 1 for a strongly seasonal, growing series. What's your best next step?

Show the answer

Answer: b

The suggestion comes from rules that don't see everything. It's a starting point, and it's editable.

Check yourself

Breaks finds a shift only 10 points from the end of the series. What should you think about before training from there?

Show the answer

Answer: b

Too few points after a break can leave a model with almost nothing to fit, so check both the evidence and the length that remains.

09

Recap

Recap
  • The Series lab walks one series through the track's questions, and saves each as an analysis.
  • Its hand-off suggests differences, a season and a training start, with reasons you can override.
  • Tests produce ideas. A backtest with baselines settles them.
  • If a simple method holds up, ship the simple method.

Concepts in this lesson