quantlab.runs.trained_run.TrainedRun#

class quantlab.runs.trained_run.TrainedRun(path, kind, written_at, train_window, fitted_train_window, test_window, metrics, checkpoint, trained_on, ic_series, test_predictions, resolved_hyperparameters=None, data_fingerprint=<factory>, code=None, assembled_from=(), members=(), folds=(), cv_mean=None, index=None, seed=None)[source]#

Bases: object

One trained unit, as its run.json describes it.

Every window is (start, end), both ends inclusive, with None for a date the model was not given. A "walk_forward" unit has no windows of its own (None); its folds have.

Attributes:
pathPath

The unit’s directory.

kindstr

"model", "ensemble" or "walk_forward".

written_atstr

When run.json was written, an ISO 8601 UTC timestamp.

train_windowtuple or None

The training window as configured, before the purge; an ensemble’s covers its members’.

fitted_train_windowtuple or None

The training window actually fitted: train_window less the bars the purge drops before the test window.

test_windowtuple or None

The test window; an ensemble’s is the one every member tests on.

metricsdict

The train_* / val_* / test_* metrics of the fit, None where a metric is undefined; empty when the fit was not evaluated and for a "walk_forward" unit.

checkpointPath or None

The file load reads: a "model" unit’s checkpoint, an "ensemble" unit’s run.json; None for a "walk_forward" unit.

trained_ondict or None

What a "model" unit was trained on: factor_names, label_names and the sorted training symbols.

ic_seriesPath or None

The per-bar IC series, when written.

test_predictionsPath or None

The test-segment prediction store, when written.

resolved_hyperparametersdict or None

The hyperparameters a "model" unit’s library actually trained with, library defaults merged in; None when the model reports none. A record of the fit, not part of the rebuild recipe config.

data_fingerprintdict

What the unit’s collect() read, by component path within the model (factors.0.dataset); empty for a member or a fold, whose data their ensemble or walk-forward unit read.

codedict or None

The code record of the model it trained (git, modules, libraries); None for a member or a fold.

assembled_fromtuple of dict

For an ensemble or walk-forward unit assembled from members trained separately (BaseEnsemble.assemble), each member’s source run, in member order: its directory when assembled and its code; empty for a unit that was trained.

memberstuple of TrainedRun

An "ensemble" unit’s members, in member order; empty otherwise.

foldstuple of TrainedRun

A "walk_forward" unit’s folds, in fold order; empty otherwise.

cv_meandict or None

A "walk_forward" unit’s fold means, keyed cv_mean_{metric}, with cv_n_folds; empty when no fold has metrics, None for other kinds.

indexint or None

The fold’s index in the walk, for a unit read as a fold.

seedint or None

The seed its ensemble recorded, for a unit read as a member.

Examples

>>> run = TrainedRun.open(checkpoint)
>>> run.checkpoint == checkpoint, sorted(run.trained_on)
(True, ['factor_names', 'label_names', 'symbols'])
>>> ensemble = TrainedRun.open(ensemble_dir)
>>> ensemble.kind, [member.seed for member in ensemble.members]
('ensemble', [0, 1, 2])
property config#

The config.json that rebuilds the model of a "model" unit.

Examples

>>> TrainedRun.open(checkpoint).config["name"]
'tests.backtest_fixtures.FirstFeatureHead'
classmethod open(path)[source]#

Read the trained unit at path, with its members and folds.

Parameters:
pathPath or str

The unit’s directory, its run.json, or the checkpoint of a "model" unit.

Returns:
TrainedRun
Raises:
FileNotFoundError

If path does not exist.

ValueError

If the unit, or one of its members or folds, has no run.json or another format_version, is not a trained run, or path is a file other than the unit’s run.json or checkpoint.

Examples

>>> TrainedRun.open(checkpoint) == TrainedRun.open(checkpoint.parent)
True