HierarchicalStructure#

class HierarchicalStructure(level_structure: Dict[str, List[str]], level_names: List[str] | None = None)[source]#

Bases: BaseMixin

Represents hierarchical structure of TSDataset.

Init HierarchicalStructure.

Parameters:
  • level_structure (Dict[str, List[str]]) – Adjacency list describing the structure of the hierarchy tree (i.e. {“total”:[“X”, “Y”], “X”:[“a”, “b”], “Y”:[“c”, “d”]}).

  • level_names (List[str] | None) – Names of levels in the hierarchy in the order from top to bottom (i.e. [“total”, “category”, “product”]). If None is passed, level names are generated automatically with structure “level_<level_index>”.

Methods

get_level_depth(level_name)

Get level depth in a hierarchy tree.

get_level_segments(level_name)

Get all segments from particular level.

get_segment_level(segment)

Get level name for provided segment.

get_summing_matrix(target_level, source_level)

Get summing matrix for transition from source level to target level.

set_params(**params)

Return new object instance with modified parameters.

to_dict()

Collect all information about etna object in dict.

Attributes

This class stores its __init__ parameters as attributes.

get_level_depth(level_name: str) int[source]#

Get level depth in a hierarchy tree.

Parameters:

level_name (str) –

Return type:

int

get_level_segments(level_name: str) List[str][source]#

Get all segments from particular level.

Parameters:

level_name (str) –

Return type:

List[str]

get_segment_level(segment: str) str[source]#

Get level name for provided segment.

Parameters:

segment (str) –

Return type:

str

get_summing_matrix(target_level: str, source_level: str) csr_matrix[source]#

Get summing matrix for transition from source level to target level.

Generation algorithm is based on summing matrix structure. Number of 1 in such matrices equals to number of nodes on the source level. Each row of summing matrices has ones only for source level nodes that belongs to subtree rooted from corresponding target level node. BFS order of nodes on levels view simplifies algorithm to calculation necessary offsets for each row.

Parameters:
  • target_level (str) – Name of target level.

  • source_level (str) – Name of source level.

Returns:

Summing matrix from source level to target level

Return type:

csr_matrix

set_params(**params: dict) Self[source]#

Return new object instance with modified parameters.

Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a model in a Pipeline.

Nested parameters are expected to be in a <component_1>.<...>.<parameter> form, where components are separated by a dot.

Parameters:

**params (dict) – Estimator parameters

Returns:

New instance with changed parameters

Return type:

Self

Examples

>>> from etna.pipeline import Pipeline
>>> from etna.models import NaiveModel
>>> from etna.transforms import AddConstTransform
>>> model = model=NaiveModel(lag=1)
>>> transforms = [AddConstTransform(in_column="target", value=1)]
>>> pipeline = Pipeline(model, transforms=transforms, horizon=3)
>>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2})
Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
to_dict()[source]#

Collect all information about etna object in dict.