fuzzyclust.timeseries.bottom_up_segmentation#

fuzzyclust.timeseries.bottom_up_segmentation(X, n_components=2, max_error=None, n_segments=None, cost='q', init_length=10, center=True)[source]#

Bottom-up segmentation with PCA models (Keogh et al. style, multivariate extension).

The series is first cut into pieces of init_length samples. The cost of merging every pair of adjacent segments – the PCA cost (pca_segment_cost()) of the union – is computed and the cheapest pair is merged, until the cheapest merge would cost more than max_error or until n_segments segments are left. The cost is the level of the model error of the merged segment (not its increase), so max_error is the natural stopping rule; n_segments is offered for comparisons with a known number of segments. This is the multivariate counterpart of the piecewise-linear-approximation bottom-up algorithm (Appendix A of Abonyi et al., 2005) used there as the baseline: with the \(Q\) cost it detects changes of the correlation structure, with the \(T^2\) cost shifts of the operating point.

Parameters:
Xarray_like of shape (n_samples, n_features)
n_componentsint, default=2

Number of principal components \(p\) of the segment models.

max_errorfloat, optional

Stop when the cheapest merge costs more than this (ignored if n_segments is given).

n_segmentsint, optional

Stop when this many segments are left.

cost{“q”, “t2”}, default=”q”
init_lengthint, default=10

Length of the initial fine segments.

centerbool, default=True

Use the covariance of each segment (centered data). False uses the uncentred second-moment matrix as printed in eqs. (30)-(31) of the paper; the cost is then dominated by the level of the variables and the greedy merging becomes unreliable unless the data are centered beforehand.

Returns:
resultsklearn.utils.Bunch

labels (segment index per sample), boundaries (start indices of the segments except the first), segments (list of (start, stop) pairs), merge_costs (cost of every merge made, in order) and n_segments.

References

[1]

E. Keogh, S. Chu, D. Hart, M. Pazzani, “An online algorithm for segmenting time series”, Proc. IEEE ICDM, 2001.

[2]

J. Abonyi, B. Feil, S. Németh, P. Árva, “Modified Gath–Geva clustering for fuzzy segmentation of multivariate time-series”, Fuzzy Sets and Systems 149 (2005) 39–56, Appendix A.

Examples

>>> from fuzzyclust.timeseries import bottom_up_segmentation, make_piecewise_timeseries
>>> X, _ = make_piecewise_timeseries(n_samples=400, change_points=(200,),
...                                  change_kinds=("correlation",), random_state=0)
>>> res = bottom_up_segmentation(X, n_components=2, n_segments=2)
>>> res.n_segments, abs(int(res.boundaries[0]) - 200) <= 10
(2, True)

Examples using fuzzyclust.timeseries.bottom_up_segmentation#

Bottom-up segmentation with PCA models versus fuzzy segmentation

Bottom-up segmentation with PCA models versus fuzzy segmentation