Models

This page’s code cells are executed live by Quarto every time the docs are built. q.model collects model and framework utilities:

Submodule What it is
q.model.torch framework adapter: PyTorch helpers (model summaries via torchinfo today)
q.model.selection compatibility bridge returning sklearn time-series position arrays

Aligned features, targets, metadata, named partitions, purging, and embargoes belong to q.dataset.

PyTorch model summaries: q.model.torch.summary

A thin wrapper over torchinfo: a Keras-style layer-by-layer summary with output shapes, parameter counts, and estimated memory usage — handy for sanity-checking an architecture before training. Pass input_size=(batch, ...) or a real batch via input_data=:

import torch.nn as nn

import qrt as q

net = nn.Sequential(
    nn.Linear(10, 64),
    nn.ReLU(),
    nn.Linear(64, 32),
    nn.ReLU(),
    nn.Linear(32, 1),
)
q.model.torch.summary(net, input_size=(32, 10))
==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
Sequential                               [32, 1]                   --
├─Linear: 1-1                            [32, 64]                  704
├─ReLU: 1-2                              [32, 64]                  --
├─Linear: 1-3                            [32, 32]                  2,080
├─ReLU: 1-4                              [32, 32]                  --
├─Linear: 1-5                            [32, 1]                   33
==========================================================================================
Total params: 2,817
Trainable params: 2,817
Non-trainable params: 0
Total mult-adds (Units.MEGABYTES): 0.09
==========================================================================================
Input size (MB): 0.00
Forward/backward pass size (MB): 0.02
Params size (MB): 0.01
Estimated Total Size (MB): 0.04
==========================================================================================

Array-based model selection: q.model.selection

timeseries_split delegates directly to sklearn.model_selection.TimeSeriesSplit for callers that only need positional train/test arrays:

for train_idx, test_idx in q.model.selection.timeseries_split(
    X,
    n_splits=5,
    test_size=63,
    gap=5,
):
    ...

Use q.dataset.TimeSeriesSplit or q.dataset.PurgedTimeSeriesSplit when the split must retain pandas labels, targets, weights, event metadata, named roles, or leakage diagnostics.

Back to top