LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#23
Walk-forward folds
mediumMLacceptance —~25 min
Implement walk_forward(n, folds, min_train) — expanding-window validation splits for n observations. The first min_train observations are always training; the remaining n - min_train are cut into folds contiguous test blocks of equal size, with the remainder given to the LAST block. Each fold trains on every observation before its test block. Return one row per fold: [train_start, train_end, test_start, test_end], ends inclusive.
One accuracy number is a guess; a distribution across folds is evidence. The ai quants walk-forward harness reports exactly this.
example 1
input
n=100, folds=4, min_train=20
output
[[0, 19, 20, 39], [0, 39, 40, 59], [0, 59, 60, 79], [0, 79, 80, 99]]
example 2
input
n=100, folds=3, min_train=20
output
[[0, 19, 20, 45], [0, 45, 46, 71], [0, 71, 72, 99]]
note
80 test rows into 3 folds leaves 2 over — they belong to the last fold.
constraints
- folds ≥ 1
- n - min_train ≥ folds
- min_train ≥ 1
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
▶ open in the workbench
run the same math on a real tape
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to walk_forward()
n=100, folds=4, min_train=20
expected
[[0, 19, 20, 39], [0, 39, 40, 59], [0, 59, 60, 79], [0, 79, 80, 99]]
the judge calls walk_forward() with exactly these inputs · outputs are compared to 6 decimal places
● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice