milia.anomaly.models.controllimit#

Shewhart control limit: the largest standardised deviation of any reading from its training mean.

Classes

ControlLimit([limit, contamination])

Three-sigma control limit on every reading of a profile (Shewhart; Montgomery, 2019).

ControlLimitConfig(*[, name, kind, space, ...])

Validated hyperparameters of the control-limit detector.

class milia.anomaly.models.controllimit.ControlLimit(limit=None, contamination=0.1)#

Bases: BaseDetector

Three-sigma control limit on every reading of a profile (Shewhart; Montgomery, 2019).

Each column (for a daily profile, each half-hour) is standardised by its training mean and standard deviation, and a row’s score is its largest absolute standardised deviation. The control-chart rule flags a row when any reading lies more than limit standard deviations from its mean: with limit=3 the threshold after fit() is that rule. Without a limit the threshold is the training contamination quantile, as for every detector, and calibrate() replaces either with a conformal threshold. It is the simplest baseline against which the complexity of other detectors is assessed.

Parameters:
  • limit (float | None) – Control limit in standard deviations (3 is the Shewhart rule); None uses the contamination quantile of the training scores.

  • contamination (float) – Expected share of outliers, used for the threshold when limit is None.

Examples

>>> rng = np.random.default_rng(0)
>>> train = rng.normal(size=(500, 4))
>>> ControlLimit(limit=3.0).fit(train).flag(np.array([[0.0, 0.0, 0.0, 0.0], [0.0, 5.0, 0.0, 0.0]])).tolist()
[False, True]
fit(X, y=None)#

Estimate the mean and spread of every column, and set the threshold to limit if given.

Parameters:
  • X (ArrayLike) – Training data assumed normal, shape (n_samples, n_features).

  • y (None) – Ignored; present for API consistency.

Return type:

ControlLimit

Returns:

The fitted detector.

Raises:

ValueError – If limit is not positive.

class milia.anomaly.models.controllimit.ControlLimitConfig(*, name='controllimit', kind='detector', space=SearchSpace(limit=(2.0, 4.0)), limit=None, contamination=0.1)#

Bases: BaseModelConfig

Validated hyperparameters of the control-limit detector.

Fields mirror ControlLimit’s constructor; space is the default Optuna search space. Build the detector with make("detector", "controllimit", ...) or ControlLimit(**config.params()).

Examples

>>> ControlLimitConfig().name
'controllimit'