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
Situation
Scores from several detectors (score_samples, decision_function, negative_outlier_factor_) are ranked, averaged or thresholded in one pipeline.
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.
Reason
Libraries disagree on direction and on whether the threshold sits at zero, so mixing raw outputs silently corrupts the ordering.
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
IsolationForest.score_samples is documented as the opposite of the original paper's anomaly score (lower is more abnormal); decision_function equals score_samples minus offset_, with negative values meaning outliers.
Local outlier factor exposes training-sample scores through negative_outlier_factor_, and the common estimator interface treats negative decision_function values as outliers.