sequential_split
Builtin index · Statistics & ML
result = sequential_split(X, y, [test_size=0.2])
Input: X, y, test_size · Output: result
What it is
The same shape as train_test_split on X/y/test_size, but never shuffles: the first rows become the training set, the last rows the test set, in their original order.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = sequential_split(X, y, [test_size=0.2]) | X —not documented yety —not documented yettest_size optional (default 0.2)not documented yet | result Record | Returns a Record with X_train, X_test, y_train, y_test. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
seq = sequential_split(X, y, test_size = 0.2)
print("sequential_split train rows: {rows(seq.X_train)}")
strat = stratified_split(Xc, yc, test_size = 0.3, seed = 9)
print("stratified_split train rows: {rows(strat.X_train)}")
tvt = train_val_test_split(Xc, yc, val_size = 0.2, test_size = 0.2, seed = 9)
print("train/val/test rows: {rows(tvt.X_train)}, {rows(tvt.X_val)}, {rows(tvt.X_test)}")
m = knn_model(strat.X_train, strat.y_train, 5, kind = "classification")
confusion_matrix(strat.y_test, m.predict(strat.X_test), 2)
sequential_split train rows: 96 stratified_split train rows: 140 train/val/test rows: 120, 40, 40
from statistics-ml
How it works
sequential_split(X, y, [test_size=0.2]) — the time-series- safe split: NO shuffling, ever. The first (1-test_size) fraction of rows (in original order) is train, the remainder is test. This exists as its own named builtin rather than just documentation telling a script to pass shuffle=false to train_test_split, because shuffling time-ordered data before splitting is a real, easy-to-miss correctness bug: once shuffled, "future" rows land in the training set, so a model trained on them can look artificially good on a test set that's secretly full of rows temporally *before* some of its training data — data leakage from the future, not just a style choice. Reusing train_test_split's shuffle=false path under a name that says "safe for time series" out loud is the point.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.