gale_shapley

Classes

BaseGaleShapley(name, ranked_candidates)

Base class for a member of Gale-Shapley matching.

FeatureGaleShapley(name, ranked_candidates)

Class for feature member of Gale-Shapley matching.

GaleShapleyFeatureSelectionTransform(...[, ...])

Transform that provides feature filtering by Gale-Shapley matching algorithm according to the relevance table.

GaleShapleyMatcher(segments, features)

Class for handling Gale-Shapley matching algo.

SegmentGaleShapley(name, ranked_candidates)

Class for segment member of Gale-Shapley matching.

class BaseGaleShapley(name: str, ranked_candidates: List[str])[source]

Base class for a member of Gale-Shapley matching.

Init BaseGaleShapley.

Parameters
  • name (str) – name of object

  • ranked_candidates (List[str]) – list of preferences for the object ranked descending by importance

reset_tmp_match()[source]

Break tmp current.

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.

update_tmp_match(name: str)[source]

Create match with object name.

Parameters

name (str) – name of candidate to match

class FeatureGaleShapley(name: str, ranked_candidates: List[str])[source]

Class for feature member of Gale-Shapley matching.

Init BaseGaleShapley.

Parameters
  • name (str) – name of object

  • ranked_candidates (List[str]) – list of preferences for the object ranked descending by importance

check_segment(segment: str) bool[source]

Check if given segment is better than current match according to preference list.

Parameters

segment (str) – segment to check

Returns

returns True if given segment is a better candidate than current match.

Return type

is_better

reset_tmp_match()

Break tmp current.

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.

update_tmp_match(name: str)

Create match with object name.

Parameters

name (str) – name of candidate to match

class GaleShapleyFeatureSelectionTransform(relevance_table: etna.analysis.feature_relevance.relevance.RelevanceTable, top_k: int, features_to_use: Union[List[str], Literal['all']] = 'all', use_rank: bool = False, return_features: bool = False, **relevance_params)[source]

Transform that provides feature filtering by Gale-Shapley matching algorithm according to the relevance table.

Transform works with any type of features, however most of the models works only with regressors. Therefore, it is recommended to pass the regressors into the feature selection transforms.

As input, we have a table of relevances with size \(N\_{f} imes N\_{s}\) where \(N\_{f}\) – number of features, \(N\_{s}\) – number of segments. Procedure of filtering features consist of :math:`lceil

rac{k}{N_{s}} ceil` iterations.

Algorithm of each iteration:

according to the relevance table, during the matching segments send proposals to features; - select features to add by taking matched feature for each segment; - add selected features to accumulated list of selected features taking into account that this list shouldn’t exceed the size of top_k; - remove added features from future consideration.

Init GaleShapleyFeatureSelectionTransform.

Parameters
  • relevance_table (etna.analysis.feature_relevance.relevance.RelevanceTable) – class to build relevance table

  • top_k (int) – number of features that should be selected from all the given ones

  • features_to_use (Union[List[str], Literal['all']]) – columns of the dataset to select from if “all” value is given, all columns are used

  • use_rank (bool) – if True, use rank in relevance table computation

  • return_features (bool) – indicates whether to return features or not.

fit(ts: etna.datasets.tsdataset.TSDataset) etna.transforms.base.Transform

Fit the transform.

Parameters

ts (etna.datasets.tsdataset.TSDataset) – Dataset to fit the transform on.

Returns

The fitted transform instance.

Return type

etna.transforms.base.Transform

fit_transform(ts: etna.datasets.tsdataset.TSDataset) etna.datasets.tsdataset.TSDataset

Fit and transform TSDataset.

May be reimplemented. But it is not recommended.

Parameters

ts (etna.datasets.tsdataset.TSDataset) – TSDataset to transform.

Returns

Transformed TSDataset.

Return type

etna.datasets.tsdataset.TSDataset

get_regressors_info() List[str]

Return the list with regressors created by the transform.

Return type

List[str]

inverse_transform(ts: etna.datasets.tsdataset.TSDataset) etna.datasets.tsdataset.TSDataset

Inverse transform TSDataset.

Apply the _inverse_transform method.

Parameters

ts (etna.datasets.tsdataset.TSDataset) – TSDataset to be inverse transformed.

Returns

TSDataset after applying inverse transformation.

Return type

etna.datasets.tsdataset.TSDataset

classmethod load(path: pathlib.Path) typing_extensions.Self

Load an object.

Warning

This method uses dill module which is not secure. It is possible to construct malicious data which will execute arbitrary code during loading. Never load data that could have come from an untrusted source, or that could have been tampered with.

Parameters

path (pathlib.Path) – Path to load object from.

Returns

Loaded object.

Return type

typing_extensions.Self

params_to_tune() Dict[str, etna.distributions.distributions.BaseDistribution][source]

Get default grid for tuning hyperparameters.

This grid tunes parameters: top_k, use_rank. Other parameters are expected to be set by the user.

For top_k parameter the maximum suggested value is not greater than self.top_k.

Returns

Grid to tune.

Return type

Dict[str, etna.distributions.distributions.BaseDistribution]

save(path: pathlib.Path)

Save the object.

Parameters

path (pathlib.Path) – Path to save object to.

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.

transform(ts: etna.datasets.tsdataset.TSDataset) etna.datasets.tsdataset.TSDataset

Transform TSDataset inplace.

Parameters

ts (etna.datasets.tsdataset.TSDataset) – Dataset to transform.

Returns

Transformed TSDataset.

Return type

etna.datasets.tsdataset.TSDataset

class GaleShapleyMatcher(segments: List[etna.transforms.feature_selection.gale_shapley.SegmentGaleShapley], features: List[etna.transforms.feature_selection.gale_shapley.FeatureGaleShapley])[source]

Class for handling Gale-Shapley matching algo.

Init GaleShapleyMatcher.

Parameters
static break_match(segment: etna.transforms.feature_selection.gale_shapley.SegmentGaleShapley, feature: etna.transforms.feature_selection.gale_shapley.FeatureGaleShapley)[source]

Break match between segment and feature.

Parameters
static match(segment: etna.transforms.feature_selection.gale_shapley.SegmentGaleShapley, feature: etna.transforms.feature_selection.gale_shapley.FeatureGaleShapley)[source]

Build match between segment and feature.

Parameters
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.

class SegmentGaleShapley(name: str, ranked_candidates: List[str])[source]

Class for segment member of Gale-Shapley matching.

Init SegmentGaleShapley.

Parameters
  • name (str) – name of segment

  • ranked_candidates (List[str]) – list of features sorted descending by importance

get_next_candidate() Optional[str][source]

Get name of the next feature to try.

Returns

name of feature

Return type

name

reset_tmp_match()

Break tmp current.

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.

update_tmp_match(name: str)[source]

Create match with given feature.

Parameters

name (str) – name of feature to match