Skip to content
ML Academy

Classical ML, validation, metrics, interpretation, debugging · insight-1184

Verify the sign convention of an anomaly score before ranking, thresholding or comparing detectors

Evidence type
documented fact
Difficulty
easy
Roles
Data scientist, ML engineer
Industries
cross-industry

Summary: situation, action, reason, boundary

  1. Situation

    Scores from several detectors (score_samples, decision_function, negative_outlier_factor_) are ranked, averaged or thresholded in one pipeline.

  2. Action

    Wrap every detector in an adapter that returns higher means more anomalous, and unit test it with a planted extreme row that must rank first. Record the contamination or offset behind any binary label.

  3. Reason

    Libraries disagree on direction and on whether the threshold sits at zero, so mixing raw outputs silently corrupts the ordering.

  4. Boundary

    Ensembles of detectors and review queues built from library scores.

Symptom or risk

scikit-learn's IsolationForest.score_samples is the opposite of the original paper's score, so lower means more abnormal; a reversed sign puts the most normal rows at the top of the review list and averaged ranks cancel out.

Exceptions

Single-detector pipelines that only use predict labels.

Trade-offs

One more layer of code to maintain.

Pitfalls

Checking the sign on a toy dataset with no ties and assuming the offset is the same for another contamination setting.

Lessons and concepts

Claims and their sources