hierarchical_structure

Classes

HierarchicalStructure(level_structure[, ...])

Represents hierarchical structure of TSDataset.

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

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 (Optional[List[str]]) – 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>”.

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) scipy.sparse._csr.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

scipy.sparse._csr.csr_matrix

set_params(**params: dict) etna.core.mixins.TMixin

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 – Estimator parameters

  • self (etna.core.mixins.TMixin) –

  • params (dict) –

Returns

New instance with changed parameters

Return type

etna.core.mixins.TMixin

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()

Collect all information about etna object in dict.