---
title: 'DIFFI: Depth-based Isolation Forest Importance'
url: https://www.emergentmind.com/topics/depth-based-isolation-forest-feature-importance-diffi
type: topic
---

# DIFFI: Depth-based Isolation Forest Importance

Searching arXiv for DIFFI and related explainable anomaly detection papers.
arXiv search query: DIFFI Isolation Forest feature importance anomaly detection.
Depth-based Isolation Forest Feature Importance (DIFFI) is an interpretability framework for Isolation Forest in unsupervised anomaly detection. The method was introduced to address a specific limitation of Isolation Forest: although the algorithm is widely adopted because of its proven effectiveness and low computational complexity, its random splitting mechanism makes the resulting anomaly score difficult to interpret. The original preprint presents DIFFI as a set of effective, yet computationally inexpensive, methods for defining feature-importance scores at both global and local level for Isolation Forest, together with a procedure for unsupervised feature selection for anomaly detection problems [2007.11117].

## 1. Origin, scope, and problem addressed

Anomaly detection is an unsupervised learning task aimed at detecting anomalous behaviours with respect to historical data. In multivariate anomaly detection, a complex system or observed phenomenon is summarized by a single indicator, typically called an anomaly score. The attractiveness of this setting lies both in the use of multivariate information and in the fact that no human tagging is required [2007.11117].

Within this setting, Isolation Forest is one of the most commonly adopted algorithms. The motivation for DIFFI is the lack of interpretability in Isolation Forest, described as an effect of the inherent randomness governing the splits performed by the Isolation Trees that compose the forest. DIFFI targets precisely that gap by assigning feature-importance scores to the variables involved in isolation. The original work further states that the same interpretability mechanism can be used to perform unsupervised feature selection and to tackle feature-importance evaluation in unsupervised anomaly detection [2007.11117].

Later application papers describe DIFFI as a model-specific method for explaining why an instance is isolated quickly, with two main explanatory modes: local per-instance attributions and global feature importance over a set of anomalous or otherwise selected instances. In those descriptions, DIFFI is explicitly tied to the internal structure of Isolation Forest rather than to external perturbation or surrogate modeling [2507.15643].

## 2. Dependence on Isolation Forest mechanics

The explanatory logic of DIFFI inherits the mechanics of Isolation Forest. Let the dataset be $X = \{x_i\}_{i=1}^n \subset \mathbb{R}^d$, where $d$ is the number of features. Isolation Forest builds an ensemble of $T$ binary trees, each trained on a subsample of size $\ell$. Each tree recursively isolates points by randomly selecting a feature and a split threshold until a termination condition is reached. For an instance $x$, the path length in tree $t$ is the number of edges traversed from the root to the external node, denoted $h_t(x) \in \mathbb{N}$. The expected path length is
$$
E[h(x)] = \frac{1}{T}\sum_{t=1}^T h_t(x),
$$
and the anomaly score is
$$
s(x,\ell)=2^{-E[h(x)]/c(\ell)},
$$
where
$$
c(\ell)=2H(\ell-1)-2(\ell-1)/\ell,
$$
with $H(m)=\sum_{k=1}^m 1/k$ the $m$-th harmonic number. Small $E[h(x)]$ implies $s(x,\ell)$ close to $1$, whereas large $E[h(x)]$ yields $s(x,\ell)$ close to $0$ [2507.15643].

DIFFI uses this path-based structure directly. Its basic intuition is that the features that participate in early isolation should receive higher importance than those that appear only in deeper parts of the tree. A common misconception is that simple path-based counting is sufficient. A later comparative discussion states that path-based attributions without depth weighting treat early and late splits equally and therefore miss Isolation Forest’s core intuition that isolation is mostly done early [2507.15643].

## 3. Local attribution and depth weighting

A self-contained mathematical description of Local-DIFFI is given in a shared-mobility study that adopts the method. For each tree $t$, let $P_t(x)$ be the ordered set of internal nodes visited by $x$ from root to leaf, let $depth_t(v)$ be the depth of node $v$, and let $f(v)\in\{1,\dots,d\}$ be the index of the feature used at node $v$. DIFFI then uses a decreasing depth-weighting function
$$
w(d)=(d+1)^{-p}, \qquad p\ge 1,
$$
with default $p=1$. The per-tree, per-instance importance for feature $j$ is
$$
I_j^{(t)}(x)=\sum_{v\in P_t(x),\, f(v)=j} w(depth_t(v)),
$$
and aggregation across trees yields
$$
I_j(x)=\frac{1}{T}\sum_{t=1}^T I_j^{(t)}(x).
$$
An optional normalization produces
$$
\hat{Z}_j(x)=\frac{I_j(x)}{\sum_{k=1}^d I_k(x)},
$$
so that $\sum_{j=1}^d \hat{Z}_j(x)=1$. These normalized local importances are described there as Local-DIFFI [2507.15643].

This formulation makes several implementation choices explicit. Root depth is set to $0$, so the first split has weight $w(0)=1$ when $p=1$. DIFFI attributes contributions only at internal split nodes along the path; external or leaf nodes do not add feature attribution. The method therefore interprets the explanatory signal as arising from the sequence of internal decisions that isolate the point, not from the terminal leaf itself [2507.15643].

The same source emphasizes that DIFFI works entirely from the learned forest structure and requires no additional model fitting or perturbation sampling. Per instance, traversing one tree takes $O(\mathrm{avg\_depth}) \approx O(\log \ell)$ on average, and for $T$ trees the per-instance complexity is $O(T\log \ell)$ [2507.15643].

## 4. Global importance, outlier–inlier contrast, and feature selection

One global aggregation strategy averages normalized local scores over a set $S$ of instances, such as all detected anomalies or a filtered subset:
$$
I_j^{global}(S)=\frac{1}{|S|}\sum_{x\in S}\hat{Z}_j(x).
$$
The same formulation also allows anomaly-score weighting,
$$
I_j^{global,w}(S)=\frac{\sum_{x\in S} s(x,\ell)\hat{Z}_j(x)}{\sum_{x\in S} s(x,\ell)}.
$$
This yields global rankings that summarize the most influential features in driving anomalies system-wide or within a subset such as a time window or operational regime [2507.15643].

A distinct global formulation appears in an EV-charging study. There, DIFFI maintains cumulative feature-importance vectors for predicted inliers and predicted outliers, $I_I$ and $I_O$, together with feature-usage counters $V_I$ and $V_O$. For an internal node, an induced imbalance coefficient is defined as
$$
\lambda(v)=
\begin{cases}
0 & \text{if } n_l(k)=0 \text{ or } n_r(k)=0 \\
\tilde{\lambda}(k) & \text{otherwise}
\end{cases}
$$
with
$$
\tilde{\lambda}(k)=g\!\left(\frac{\max(n_l(k),n_r(k))}{n(k)}\right),
\qquad
g(a)=\frac{a-\lambda_{min}(n)}{2(\lambda_{max}(n)-\lambda_{min}(n))}+0.5.
$$
When a point traverses a node that splits on feature $f_j$, the update is
$$
\Delta=\cfrac{1}{h_t(x_I)}\lambda_I(v),
$$
and the global feature importance is then computed elementwise as
$$
GFI=\cfrac{I_O/V_O}{I_I/V_I}.
$$
This version explicitly contrasts outlier and inlier behaviour while correcting for how often each feature is used along paths [2507.15718].

The original DIFFI preprint states that the interpretability procedure also serves to perform unsupervised feature selection [2007.11117]. Later case studies make that role concrete. In the EV-charging study, the authors retained only the nine most important features from the global ranking to simplify subsequent analysis and improve interpretability [2507.15718]. A plausible implication is that DIFFI is used not only as a post hoc explanation tool but also as a dimensionality-reduction mechanism tailored to anomaly detection.

## 5. Empirical uses and relation to other explainability methods

The original DIFFI preprint reports evaluation on several synthetic and real-world datasets, including comparisons against state-of-the-art interpretability techniques, and states that the code was made publicly available to enhance reproducibility and foster research in the field [2007.11117].

A shared-mobility application uses Isolation Forest with DIFFI on station-hour observations in Boston/Cambridge for January 2023. The inputs include in/out traffic load, ratio of subscribers to on-demand users, average distance, duration, linear speed, timing variables, weather variables, neighborhood type, and nearby MBTA stops within $300\,\mathrm{m}$. In that study, Local-DIFFI consistently ranked temperature, neighborhood, and day of week highly; transit accessibility emerged as critical; anomaly spikes occurred around $8$ a.m. and on Thursdays; Jan 15 showed elevated anomalies under the highest wind speeds; and Jan 26 showed widespread anomalies under heavy rainfall of $2.6\,\mathrm{cm}$. For the subset of anomalies concentrated at $8$ a.m. on Thursdays, Local-DIFFI highlighted public transit availability, trip duration, trip speed, wind speed, and precipitation as dominant contributors [2507.15643].

An EV-charging application studies eight charging stations from Jan 2022 to Jun 2024 and analyzes 22,986 full recharges after removing sessions with missing or incomplete information. The feature space includes aggregate session variables, power descriptors, temperature descriptors, and the cross-signal correlation $Corr_{P-T}$. Global DIFFI ranked temperature kurtosis $T_{kurt}$, temperature number of peaks $T_{npeaks}$, and temperature correlation lag $T_{corrlag}$ as the top three features. Local-DIFFI on anomalous points was then used to rank features per anomaly, and domain experts judged the explanations reasonable and consistent with field experience [2507.15718].

Both application papers position DIFFI against SHAP. In the shared-mobility study, SHAP and DIFFI surfaced similar top features, and Local-DIFFI ran in $0.293\,\mathrm{s}$ per sample versus $5.955\,\mathrm{s}$ for SHAP on a consumer laptop [2507.15643]. In the EV-charging study, the comparison is qualitative rather than metric-based, but the reported conclusion is similar: DIFFI and SHAP highlight similar influential features, while DIFFI is preferred in a time-sensitive, large-scale setting because of substantially lower computational cost [2507.15718].

## 6. Methodological considerations, limitations, and open directions

Several implementation constraints recur across the later DIFFI literature. Standard Isolation Forest implementations such as scikit-learn accept only numerical features, so categorical variables must be encoded numerically; Isolation Forest does not handle NaNs, so missing inputs must be imputed before training and explaining; and randomness in feature and threshold selection requires a fixed `random_state` for reproducibility [2507.15643]. These are operational constraints of the underlying detector, but they directly affect DIFFI because DIFFI inherits the forest structure.

The method also has substantive limitations. Reported limitations include split-frequency bias, in which features that frequently appear in splits can accrue importance; difficulty in deconvolving correlated predictors because DIFFI is path-based; and sensitivity of interpretability to encoding choices for categorical variables [2507.15643]. The EV-charging study adds that rankings may still vary with different random seeds or data subsamples, even though DIFFI averages across trees and normalizes by feature-use counters, and recommends interpreting groups of correlated features jointly [2507.15718].

These limitations clarify what DIFFI is and is not. It is not a model-agnostic attribution framework; it is tailored to Isolation Forest and exploits the semantics of path depth and split structure. It is not a full interaction model either: SHAP-based approaches are described as theoretically principled additive attributions that can capture interaction effects, whereas DIFFI is favored for simplicity and speed in tree-based anomaly detection [2507.15643]. Future improvements proposed in the shared-mobility study include adaptive depth weighting, incorporation of node mass into the weighting function, and hybrid DIFFI-plus-perturbation schemes [2507.15643].

In this form, DIFFI occupies a specific methodological niche: it converts the isolation mechanism of Isolation Forest into local and global feature rankings, supports unsupervised feature selection, and provides explanations that are computationally lightweight enough for operational anomaly-analysis workflows [2007.11117].

Source: https://www.emergentmind.com/topics/depth-based-isolation-forest-feature-importance-diffi