[ENH] Add Extended Isolation Forest anomaly detector (#2113)#3626
[ENH] Add Extended Isolation Forest anomaly detector (#2113)#3626CedricConday wants to merge 1 commit into
Conversation
Direct, dependency-free implementation of the Extended Isolation Forest (Hariri et al., 2021) as a series anomaly detector, alongside the existing IsolationForest. Trees split on random hyperplanes rather than axis-parallel cuts, with an extension_level parameter; extension_level=0 recovers the standard Isolation Forest. Follows the existing sliding-window detector pattern and supports uni/multivariate, unsupervised and semi-supervised use.
Thank you for contributing to
|
Fixes #2113.
Adds
ExtendedIsolationForest, a series anomaly detector implementing the Extended Isolation Forest (Hariri et al., 2021), next to the existingIsolationForest.Following the discussion in the issue, this is a direct implementation rather than a wrapper of the
eifpackage: the isolation trees split on random hyperplanes(x - p) · n <= 0instead of axis-parallel cuts, and anextension_levelparameter sets how many components of the normal vector are non-zero.extension_level=0zeroes all but one component and recovers the standard axis-parallel Isolation Forest;n_features - 1(the default whenNone) uses fully oriented hyperplanes. The detector reuses the existing sliding-window pattern (window_size,stride,reverse_windowing) and supports univariate, multivariate, unsupervised and semi-supervised use.Why a direct implementation: it needs no new dependency (pure NumPy), and the
eifreference package has not been updated in ~5 years and no longer installs on current toolchains, so a wrapper would be fragile.Validation I ran locally (throwaway script, not committed):
extension_level=0the window scores rank-correlate withsklearn.ensemble.IsolationForeston identical windows at Spearman ≈ 0.97, i.e. the model reduces to the original algorithm as expected.random_state.Worth a careful look:
c(n)normalisation and the score formula2 ** (-E[h(x)] / c(psi)).extension_level=None → n_features - 1is the right default.Tests: 9 unit tests covering uni/multivariate, stride, no-window, semi-supervised, determinism, the
extension_level=0reduction, and parameter validation; the estimator also passescheck_estimator.pre-commitis clean.This pull request includes code written with the assistance of AI. The code has not yet been reviewed by a human.