Saltar al contenido principal

RollingOriginSplitter

Splitter
DashAI.back.splitters.RollingOriginSplitter

Cross-validate a series by walking the origin forward through time.

Each fold trains on everything up to a point and is scored on the rows just after it, then the point moves forward and the model is refitted with more history. The training window only ever grows.

With four origins, a horizon of one and a reserved tail::

Reserved test, in no fold: Nov Dec

Fold 1: train Jan Feb Mar | validation Apr Fold 2: train Jan .. Apr | validation May Fold 3: train Jan .. May | validation Jun Fold 4: train Jan .. Jun | validation Jul

Final: train Jan .. Oct | test Nov Dec

This is what k-fold cannot do for a series: its folds train on rows that come after the ones they score, which measures interpolation rather than forecasting and reports a number that will not survive contact with real use.

The size of the first training window is not asked for. It follows from the other three settings, since the last origin has to leave a full horizon of rows to score::

initial_train_size = n - horizon - (n_splits - 1) * step

Row order is taken as time order, and the reserved rows are the tail rather than a random sample, which is what TEST_SPLIT_STRATEGY = "temporal" selects in the base class.

Parameters

n_splits : integer, default=5
How many times the model is refitted and scored, each time with more history than the last.
horizon : integer, default=1
How many steps ahead each refit is scored on.
step : integer, default=1
How many rows the origin advances between one refit and the next.
test_size : number, default=0.1
Proportion of the most recent rows held back from every origin, used once to score the final model.

Methods

split_indexes(self, x: "'DashAIDataset'", y: "'DashAIDataset'") -> 'List[Tuple[List, List]]'

Defined on RollingOriginSplitter

Build one expanding train and validation pair per origin.

Parameters

x : DashAIDataset
The rows left after the reserved tail was carved off.
y : DashAIDataset
Target values associated with x. Unused: where the cuts fall depends only on position, never on the target.

Returns

list[tuple[List, List]]
One (train, validation) pair per origin, as positions within the pool. The caller maps them back to original rows.

explainable_partitions(cls, split_indexes)

Defined on FoldSplitter

Return the partitions of a fold based run an explainer may target.

Parameters

split_indexes : dict
The Run.split_indexes payload, already parsed.

Returns

dict
Row indexes for the train and test partitions.

explainable_splits(cls, split_indexes: 'Dict[str, Any]') -> 'List[Dict[str, Any]]'

Defined on BaseSplitter

Describe the partitions of a run that an explainer may target.

Parameters

split_indexes : dict
The Run.split_indexes payload, already parsed.

Returns

list[dict]
One {"name", "rows"} entry per non-empty partition, followed by an all entry. Empty when the run has no data to explain.

get_credential(self, name: str)

Defined on ConfigObject

Resolve a registered credential component by name.

Parameters

name : str
Credential component class name (e.g. "HuggingFaceCredential").

Returns

BaseCredential
An instance of the requested credential component.

get_metadata(cls) -> 'dict'

Defined on FoldSplitter

Return metadata describing the splitter's compatibility.

get_schema(cls) -> dict

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

prepare_y(self, y)

Defined on BaseSplitter

Encode the target variable for stratified splitting.

Parameters

y : object
Target values to encode. This may be a list, a pandas-like object, or a DashAI dataset that exposes a single target column.

Returns

object
Encoded labels suitable for stratified splitting.

split(self, x: 'DashAIDataset', y: 'DashAIDataset') -> 'Tuple[List[DatasetDict], List[DatasetDict], Dict[str, Any]]'

Defined on FoldSplitter

Create folds and return both the partitioned datasets and the indices.

Parameters

x : DashAIDataset
Input dataset to split.
y : DashAIDataset
Target values associated with x.

Returns

tuple[list, list, dict]
A tuple containing the split datasets for every fold and a mapping from fold names to their corresponding train/test indices.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.

Parameters

raw_data : dict
A dictionary with the data provided by the user to initialize the model.

Returns

dict
A validated dictionary with the necessary objects.

Compatible with