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:
objectOne trained unit, as its
run.jsondescribes it.Every window is
(start, end), both ends inclusive, withNonefor 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.jsonwas 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_windowless 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,Nonewhere a metric is undefined; empty when the fit was not evaluated and for a"walk_forward"unit.- checkpointPath or None
The file
loadreads: a"model"unit’s checkpoint, an"ensemble"unit’srun.json; None for a"walk_forward"unit.- trained_ondict or None
What a
"model"unit was trained on:factor_names,label_namesand the sorted trainingsymbols.- 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 recipeconfig.- 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: itsdirectorywhen assembled and itscode; 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, keyedcv_mean_{metric}, withcv_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.jsonthat 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
pathdoes not exist.- ValueError
If the unit, or one of its members or folds, has no
run.jsonor anotherformat_version, is not a trained run, orpathis a file other than the unit’srun.jsonor checkpoint.
Examples
>>> TrainedRun.open(checkpoint) == TrainedRun.open(checkpoint.parent) True