Outlier Detection

Detect anomalies in numeric data using Isolation Forest. Identify outliers using the Isolation Forest algorithm. Points with high anomaly scores are flagged as…

Identify outliers using the Isolation Forest algorithm. Points with high anomaly scores are flagged as potential anomalies based on the contamination threshold.

How does Isolation Forest detect outliers?

Isolation Forest is an unsupervised machine learning algorithm for anomaly detection, based on the principle that outliers are 'few and different' — they are easier to isolate than normal points. Unlike distance-based methods, it does not compute distances or densities, making it highly efficient for large datasets.

The algorithm builds an ensemble of random isolation trees. Each tree recursively partitions data by randomly selecting a feature and a split value. Anomalies, being rare and distinct, require fewer splits to isolate (shorter path length from root to leaf). Normal points, being clustered, require more splits.

The anomaly score is derived from the average path length across all trees, normalized by the expected path length for the dataset size. Scores close to 1 indicate anomalies; scores close to 0.5 indicate normal points. The contamination parameter sets the expected proportion of anomalies, determining the score threshold for classification.

Formula: Anomaly Score s(x, n) = 2^(-E(h(x)) / c(n)) c(n) = 2H(n-1) - 2(n-1)/n H(i) = ln(i) + Euler's constant s ≈ 1: anomaly s ≈ 0.5: normal s ≈ 0: very dense cluster

Example Calculation

100 data points with contamination = 0.05 (expect ~5 outliers). 100 isolation trees built. Point A has average path length 3.2 (quickly isolated → anomaly score 0.82 → flagged). Point B has average path length 8.7 (hard to isolate → anomaly score 0.45 → normal). 4 points exceed the threshold — flagged as anomalies.

When to Use This Calculator

Common Mistakes to Avoid

How to Interpret Results

Related Standards & References

Frequently Asked Questions

How do I set the contamination parameter?

Contamination is the expected proportion of anomalies in your data. If you know the historical anomaly rate (e.g., 2% defect rate), use that value. If unknown, start with 0.05-0.10 and adjust based on domain expertise. Too low → miss real anomalies; too high → flag normal points as anomalies. Visual inspection of flagged points helps calibrate.

When should I use Isolation Forest vs other outlier detection methods?

Isolation Forest excels with high-dimensional data, large datasets, and when outliers are globally distinct. Use LOF when local density matters (outliers relative to their neighborhood). Use statistical methods (Z-score, IQR) for simple univariate data. Use DBSCAN when you also need clustering. Isolation Forest's O(n log n) complexity makes it the most scalable option.