base¶
Classes
|
Modes allowed for clustering distance computation. |
|
Base class for hierarchical clustering. |
- class HierarchicalClustering(distance: etna.clustering.distances.base.Distance)[source]¶
Base class for hierarchical clustering.
Init HierarchicalClustering.
- Parameters
distance (etna.clustering.distances.base.Distance) –
- build_clustering_algo(n_clusters: int = 30, linkage: Union[str, etna.clustering.hierarchical.base.ClusteringLinkageMode] = ClusteringLinkageMode.average, **clustering_algo_params)[source]¶
Build clustering algo (see
sklearn.cluster.AgglomerativeClustering
) with given params.- Parameters
n_clusters (int) – number of clusters to build
linkage (Union[str, etna.clustering.hierarchical.base.ClusteringLinkageMode]) – rule for distance computation for new clusters, allowed “ward”, “single”, “average”, “maximum”, “complete”
Notes
Note that it will reset previous results of clustering in case of reinit algo.
- build_distance_matrix(ts: etna.datasets.tsdataset.TSDataset)[source]¶
Compute distance matrix with given ts and distance.
- Parameters
ts (etna.datasets.tsdataset.TSDataset) – TSDataset with series to build distance matrix
distance – instance if distance to compute matrix
- fit_predict() Dict[str, int] [source]¶
Fit clustering algorithm and predict clusters according to distance matrix build.
- Returns
dict in format {segment: cluster}
- Return type
Dict[str, int]
- get_centroids(**averaging_kwargs) pandas.core.frame.DataFrame [source]¶
Get centroids of clusters.
- Returns
dataframe with centroids
- Return type
pd.DataFrame
- 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 aPipeline
.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.