Isolation Forest and DBSCAN detect outliers using fundamentally different principles. Isolation Forest finds points that are easy to isolate by random partitioning — they sit in low-density areas far from the majority. DBSCAN identifies dense clusters and marks any point that does not belong to a sufficiently dense neighbourhood as noise. Both methods find outliers, but they find different kinds, and choosing only one can hide important anomalies.
Why anomaly detection method choice matters
Outlier detection is not one-size-fits-all. Global outliers — points that are unusual by any measure — are found reliably by Isolation Forest. Local outliers — points that are unusual only relative to their immediate neighbours — are better captured by density-based methods like DBSCAN. Some datasets contain both types.
A training dataset with even 3–5% contamination from unchecked anomalies can meaningfully bias learned feature statistics, corrupt distance-based features, and inflate evaluation metrics. Detecting anomalies before training — and validating them before removal — is a standard step in robust ML data preparation.
How Isolation Forest works
Isolation Forest builds an ensemble of random decision trees. At each step, it randomly selects a feature and a random split point within that feature's range. Points that are isolated quickly — in few splits — are anomalous because they require less partitioning to separate from the rest. Normal points cluster together and require many splits.
Isolation Forest produces an anomaly score between -1 and 1 (or a normalised equivalent). Points below a contamination threshold are flagged as outliers.
Strengths: - Works well in high-dimensional tabular data where DBSCAN struggles - Scales efficiently — O(n log n) complexity - Does not require specifying cluster shapes - Provides a continuous anomaly ranking, not just a binary label - Robust to varying densities across the feature space
Weaknesses: - Can miss local outliers in datasets with multiple distinct clusters of different densities - Sensitive to the contamination hyperparameter, which must be estimated
How DBSCAN works
DBSCAN (Density-Based Spatial Clustering of Applications with Noise) groups points that are densely connected — within radius eps of at least min_samples other points. Points that cannot be assigned to any dense cluster are labelled as noise, which is the DBSCAN equivalent of an outlier.
Strengths: - Naturally identifies local outliers — points unusual relative to their nearest neighbours - Discovers clusters of arbitrary shapes (not just spherical) - Does not require specifying the number of clusters - Particularly effective when outliers occupy genuine gaps between distinct data groups
Weaknesses:
- Sensitive to eps and min_samples parameter choices, which can be hard to estimate
- Struggles with high-dimensional data because density becomes less meaningful in many dimensions
- Computationally expensive at large scale — O(n²) in the worst case without spatial indexing
- Does not produce a continuous anomaly score; points are either noise or cluster members
Practical comparison and workflow
- Standardise numeric features. Both methods are sensitive to scale differences — a feature in thousands will dominate one measured in fractions unless normalised.
- Run Isolation Forest for a broad anomaly ranking across the full dataset.
- Run DBSCAN for density-based noise detection, particularly if the dataset contains known cluster structure.
- Compare which rows each method flags. Rows flagged by both are the highest-confidence outliers.
- Review rows flagged by only one method separately — these may be local anomalies (DBSCAN only) or globally unusual rows that do not violate local density (Isolation Forest only).
- Validate flagged rows using domain knowledge and feature context before deciding whether to remove, keep, or relabel them.
Use xariff's Outlier Detector to run Isolation Forest, DBSCAN, and an ensemble view in a single upload — including feature-level contribution signals to understand what makes each flagged row unusual.
Using ensemble anomaly detection
An ensemble combines the anomaly scores or labels from multiple methods and flags rows that score as anomalous across most methods. Ensemble detection is more conservative — it reduces false positives — while still capturing the breadth of outlier types that individual methods would miss.
The ensemble approach is especially valuable when the cost of incorrectly removing a valid data point is high (such as rare event data or minority class examples in imbalanced datasets).
FAQ
Which method is better for tabular data?
Isolation Forest is generally the better default for tabular data, especially when the feature space has more than five or six dimensions. DBSCAN becomes especially useful when the dataset has a known cluster structure and you want to identify points that fall between or outside those clusters. For most practical ML data cleaning use cases, start with Isolation Forest and add DBSCAN as a secondary check.
Why do Isolation Forest and DBSCAN disagree on which rows are outliers?
They define abnormality differently. Isolation Forest measures global isolation — how easily a point can be separated from the entire dataset. DBSCAN measures local density — whether a point belongs to a dense neighbourhood. A point can be globally typical but locally isolated (flagged by DBSCAN but not Isolation Forest), or globally unusual but surrounded by a small local cluster (flagged by Isolation Forest but not DBSCAN). Both are valid forms of anomaly.
Are univariate outlier checks enough for ML datasets?
Not usually. Looking at individual column distributions finds values that are extreme in a single feature. But multivariate outliers — rows that look normal column by column but are anomalous as feature combinations — are invisible to univariate checks. A person with a moderate age and a moderate income is not unusual on either dimension alone, but a very young person with very high income may be anomalous as a combination. Isolation Forest and DBSCAN catch multivariate outliers that univariate IQR or Z-score methods miss entirely.
Should I remove all detected outliers before training?
No. Some flagged rows represent genuine rare cases that the model should learn from — particularly in imbalanced datasets where rare examples carry important signal. Others are data entry errors that would harm training. Review flagged rows by domain context, the feature values that triggered the flag, and the severity of the anomaly score before deciding. Automatic bulk removal of outliers is a common and costly mistake.
How do I choose the contamination parameter for Isolation Forest?
The contamination parameter is your best estimate of the fraction of genuinely anomalous rows in the dataset. If you have domain knowledge (e.g. "approximately 2% of transactions are fraudulent"), use that. Without domain knowledge, values between 0.01 and 0.10 are common starting points. Avoid setting contamination above 0.15 without strong justification — at that level, the method starts flagging many valid rows.
How do I estimate eps and min_samples for DBSCAN?
A common heuristic for min_samples is 2 × (number of features), with a minimum of 5. For eps, a k-distance plot helps: sort distances to the k-th nearest neighbour for each point (using k = min_samples - 1) and look for the "elbow" — the point where distance starts increasing sharply. That elbow is a reasonable eps value. xariff's outlier tool estimates these parameters automatically from the data distribution.