MODULE REFERENCE

generic

anomx.detection.generic

Explicit adapters for user supplied scoring and detection algorithms.

GenericDetector

GenericDetector(model: Any = None, *, detect_fn: Callable | None = None, fit_fn: Callable | None = None, anomaly_label: int = 1)

Bases: Detector

Wrap a detector callable or estimator and normalize binary labels.

detect_fn(model, values) overrides detect/predict. Output must have one row per input row. By default labels are bool or {0, 1}; set anomaly_label=-1 for sklearn's {-1, 1} convention. Unknown labels raise instead of silently changing their meaning. DataFrame results add an is_anomaly column, while TimeSeries results are numeric binary series.

Signature parameters
ParameterTypeDefault
modelAnyNone
detect_fnkeyword onlyCallable | NoneNone
fit_fnkeyword onlyCallable | NoneNone
anomaly_labelkeyword onlyint1

Members

component_keyattribute
component_key = 'generic_detector'
component_discoverableattribute
fitmethod
fit(data: Any) -> GenericDetector

Fit the custom detector explicitly on training data.

Signature parameters
ParameterTypeDefault
dataAnyrequired

Returns GenericDetector

detectmethod
detect(data: Any) -> Any

Return binary labels with exactly the input observation alignment.

Signature parameters
ParameterTypeDefault
dataAnyrequired

Returns Any

GenericScorer

GenericScorer(model: Any = None, *, score_fn: Callable | None = None, fit_fn: Callable | None = None, higher_is_anomaly: bool = True)

Bases: Scorer

Wrap a scoring callable or estimator with explicit anomaly direction.

The callable receives a finite numeric array with observations on axis 0 and returns one scalar or vector per observation. Alternatively provide an estimator with score_samples, decision_function, or score. score_fn(model, values) overrides method selection. Set higher_is_anomaly=False for sklearn density/inlier scores; the adapter negates those outputs. For DataFrames, a scalar output is added as score; TimeSeries outputs preserve time coordinates. Fitting, when available, is always explicit.

Signature parameters
ParameterTypeDefault
modelAnyNone
score_fnkeyword onlyCallable | NoneNone
fit_fnkeyword onlyCallable | NoneNone
higher_is_anomalykeyword onlyboolTrue

Members

component_keyattribute
component_key = 'generic_scorer'
component_discoverableattribute
fitmethod
fit(data: Any) -> GenericScorer

Fit a user-provided scorer on the given training observations.

Signature parameters
ParameterTypeDefault
dataAnyrequired

Returns GenericScorer

scoremethod
score(data: Any) -> Any

Return finite anomaly scores; larger values always mean more anomalous.

Signature parameters
ParameterTypeDefault
dataAnyrequired

Returns Any