Repository navigation
Fix fast ABOD counting each training point as its own neighbor - #774
Open
raashish1601 wants to merge 2 commits into
Open
raashish1601 wants to merge 2 commits into
raashish1601 wants to merge 2 commits into
Conversation
raashish1601
force-pushed
the
fix/abod-fast-self-neighbor
branch
from
October 7, 2026 23:44
92234d5 to
b05f083
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions Basics:
All Submissions Cores:
In fast ABOD,
_fit_fastfinds the neighbors of the training points withself.neigh_.kneighbors(self.X_train_, ...). Querying with the training data returns each point as its own nearest neighbor, and_calculate_wocsthen skips every pair that contains the point itself, so a training score is computed from onlyn_neighbors - 1real neighbors.decision_functionusesn_neighborsneighbors for new points, sodecision_scores_(andthreshold_/labels_, which come from them) are on a different basis than the test scores. As a consequence, fast ABOD withn_neighbors = n_train - 1also does not match the default (all points) method.The fix calls
kneighbors(n_neighbors=..., return_distance=False)withoutX, which in scikit-learn excludes each training point from its own neighbors (the same approachKNNuses). Only fast ABOD training scores change;decision_functionand the default method are unchanged.Tests in
pyod/test/test_abod.py:test_fast_mode_train_scores_use_k_other_points: each training score equals-_calculate_wocsover itsn_neighborsnearest other training points.test_fast_mode_with_all_neighbors_matches_default: withn_neighbors = n - 1, fast and default give the same training scores.Both fail on the current code and pass with the change.
_numpy_abod_scores, the reference added by #766 for the dtype tests, queried the training points with the training data too (it followed the current convention), so it now also leaves each training point out of its own neighbors.pyod/test/test_abod.pypasses locally (58 tests).