Time series forest - interval-based classification.
Classes
class algorithms.timeseries.classification.interval.TimeSeriesForestClassifier(TimeSeriesClassifier)
Classification from summary statistics of random intervals.
Some series are distinguished not by a local motif or an overall shape, but by what happens in a particular stretch of time — a device that draws more current during startup, a patient whose reading trends upward only in the third hour. The time series forest draws random intervals, describes each by three cheap statistics, and lets a forest decide which stretches matter.
Because a tree can split on "the slope between t=40 and t=90", the fitted model localises where in time the difference lives, which none of the other members of this family does.
__init__( self, n_intervals: Any = 'sqrt', min_interval: int = 3, n_estimators: int = 200, estimator: Optional[Any] = None, random_state: Optional[int] = None, )
Overview
-
Draw
n_intervalsrandom intervals of random position and width. - Describe each by its mean, standard deviation and
-
Concatenate into a feature vector of
3 * n_intervalsvalues. - Fit a random forest on those features.
Theory
For an interval [a, b) the three features are
with w = b - a. Mean captures level, standard deviation captures activity, slope captures trend — between them a coarse but surprisingly effective description of a stretch of series.
The three are computed from prefix sums of x, x^2 and tx, so an interval costs O(1) whatever its width; because time is a run of consecutive integers, \mathrm{Var}(t) is the closed form (w^2 - 1)/12 and needs no accumulation at all.
Parameters
n_intervals
'sqrt' uses :math:`\lceil \sqrt{L} \rceil`, the classical choice.
min_interval
n_estimators
estimator
RandomForestClassifier.
random_state
Attributes
intervals_
[start, end) rows.
estimator_
classes_
fit.
Notes
Complexity. Feature extraction is O(n L) to build the prefix sums plus O(n k) for k intervals — the interval count does not multiply the series length. It runs in the shared C++ kernel tuiml._cpp_ext.timeseries.interval_features. The forest then dominates.
When to use. Reach for this when the discriminating information is localised in time and the series are aligned — the same phase of the same process across instances. It is the wrong choice when patterns drift in position, since an interval is fixed: there ShapeletTransformClassifier or BOSSClassifier search over positions instead. Like every member of the family it is beaten on raw accuracy by MiniRocketClassifier more often than not; its value here is a distinct, cheap, temporally localised view.
Multivariate panels are handled by extracting the same intervals from every channel and concatenating.
References
See Also
>>> import numpy as np
>>> from tuiml.algorithms.timeseries.classification import TimeSeriesForestClassifier
>>> rng = np.random.default_rng(0)
>>> # The classes differ only in the middle third of the series.
>>> X = rng.normal(0, 1.0, (80, 90))
>>> y = np.arange(80) % 2
>>> X[y == 1, 30:60] += np.linspace(0, 4, 30)
>>> model = TimeSeriesForestClassifier(n_estimators=100, random_state=0).fit(X, y)
>>> float((model.predict(X) == y).mean())
1.0
Methods
fit
(self, X: np.ndarray, y: np.ndarray) -> 'TimeSeriesForestClassifier'
fit
(self, X: np.ndarray, y: np.ndarray) -> 'TimeSeriesForestClassifier'
Draw intervals and fit the forest on their statistics.
Parameters
X
y
Returns
self
transform
(self, X: np.ndarray) -> np.ndarray
transform
(self, X: np.ndarray) -> np.ndarray
Return the interval statistics of a panel.
Parameters
X
Returns
features