Random (baseline)#

Random – baseline detector for benchmarking.

Description#

Emits uniformly random change points or state labels. Intended as a lower bound for benchmarks and for pipeline testing.

Two modes of operation:

  • Unsupervised – draws a random n_change_points and/or n_states.

  • Semi-supervised – given quantities, randomises locations/labels.

Type: state detection
Supervision: unsupervised or semi-supervised
Scope: univariate and multivariate
Complexity: \(O(n)\)

Parameters#

Name

Type

Default

Description

semi_supervised

bool

False

Enable semi-supervised mode.

n_change_points

int / None

None

Number of change points to emit.

n_states

int / None

None

Number of distinct states.

random_state

int / None

None

Random seed for reproducibility.

axis

int

0

Time axis (rows with 0, columns with 1).

Usage#

from tsseg.algorithms import RandomDetector

detector = RandomDetector(n_change_points=5, random_state=42)
labels = detector.fit_predict(X)

Implementation: Origin: new code.

Reference: none.

API reference#

Random detector producing synthetic states and change points.

class RandomDetector(*, semi_supervised=False, n_change_points=None, n_states=None, random_state=None, axis=0)[source]#

Bases: BaseSegmenter

Random detector emitting change points and state labels.

The detector is primarily intended for testing pipelines. It can operate in a purely unsupervised fashion, where the number of change points and states is drawn at random (with bounds derived from available data), or in a semi-supervised mode where those quantities are given but locations and assignments remain random.

Parameters:
  • semi_supervised (bool) – If True, n_change_points and n_states are required and used as given. If False, both counts are drawn at random and these two parameters are ignored.

  • n_change_points (int | None) – Number of change points, used when semi_supervised=True; at most n - 1 for a series of n points. 0 gives a single segment.

  • n_states (int | None) – Number of distinct states, used when semi_supervised=True; at least 2 when there is a change point.

  • random_state (int | None) – Seed of the random generator, drawn again at each fit. None gives a different segmentation at each fit.

  • axis (int) – Time axis: rows with 0, columns with 1.

breakpoints_#

Sorted change points of the last segmentation drawn.

Type:

np.ndarray of int

segment_states_#

State of each segment of that segmentation.

Type:

np.ndarray of int

state_sequence_#

State label of each time point, as returned by predict.

Type:

np.ndarray of int

n_change_points_drawn_#

Number of change points of that segmentation.

Type:

int

n_states_drawn_#

Number of states it was drawn with (not all of them need to occur).

Type:

int

Notes

Without semi_supervised, the number of change points is drawn uniformly in {3, …, min(14, n - 1)} (n - 1 change points if n < 4) and the number of states uniformly in {min(n_change_points + 1, 10), …, 10}. Change points are drawn without replacement among 1, …, n - 1, and two consecutive segments never share a state. predict on a series whose length differs from the one seen by fit draws a new segmentation.

set_fit_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in fit.

Returns:

self – The updated object.

Return type:

RandomDetector

set_predict_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in predict.

Returns:

self – The updated object.

Return type:

RandomDetector