milia.anomaly.models.reconstruction#

Reconstruction error from the leading principal components (the Q statistic of multivariate process control).

Classes

Reconstruction([components, random_state, ...])

Detector scoring a row by the squared error of its reconstruction from the leading principal components.

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

Validated hyperparameters of the reconstruction detector.

class milia.anomaly.models.reconstruction.Reconstruction(components=5, random_state=0, contamination=0.1)#

Bases: BaseDetector

Detector scoring a row by the squared error of its reconstruction from the leading principal components.

Normal rows lie close to the subspace their leading components span; a row whose shape the components cannot express leaves a large residual, the Q (squared prediction error) statistic of multivariate process control.

Parameters:
  • components (int) – Number of principal components kept, at most the number of rows and one fewer than the number of features.

  • random_state (int | None) – Seed of the PCA solver.

  • contamination (float) – Expected share of outliers, used for the default threshold.

Examples

>>> rng = np.random.default_rng(0)
>>> base = rng.normal(size=(200, 2)) @ rng.normal(size=(2, 6))
>>> model = Reconstruction(components=2).fit(base)
>>> odd = rng.normal(size=(1, 6)) * 5
>>> bool(model.score_samples(odd)[0] < model.score_samples(base[:1])[0])
True
class milia.anomaly.models.reconstruction.ReconstructionConfig(*, name='reconstruction', kind='detector', space=SearchSpace(components=(2, 12)), components=5, random_state=0, contamination=0.1)#

Bases: BaseModelConfig

Validated hyperparameters of the reconstruction detector.

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

Examples

>>> ReconstructionConfig().name
'reconstruction'