HierarchicalStructure

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

Bases: etna.core.mixins.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 (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>”.

Inherited-members

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.

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