Feature bagging in anomaly detection is an ensemble technique that trains the same base outlier detector many times, each time on a randomly chosen subset of the features, and then combines the resulting anomaly scores into one final score per data point. It was introduced by Lazarevic and Kumar in 2005 to make distance- and density-based detectors more reliable on high-dimensional data.
The idea is that an anomaly which is hidden among many irrelevant dimensions may become obvious in a smaller projection. By looking at the data through many random subspaces, feature bagging reduces the influence of noisy features and lowers the variance of a single detector such as the local outlier factor.
How feature bagging builds an outlier ensemble
The original algorithm repeats a simple loop. For each of T rounds, it draws a feature count between half of the dimensions and all dimensions minus one, samples that many features without replacement, and runs the base detector on the full set of records using only those features. Each round produces one score vector covering every observation.
Unlike classic bagging for classification, feature bagging usually keeps all data points and samples only columns. This is deliberate: removing rows could remove the rare anomalies themselves, whereas sampling columns changes the viewpoint without losing any candidate outlier.
The table below lists the parameters that define a feature bagging ensemble and their usual ranges.
| Parameter | Typical setting | Effect |
|---|---|---|
| Number of estimators | 10 to 100 | More rounds stabilize scores but cost time |
| Subspace size | Between d/2 and d minus 1 features | Smaller subsets add diversity, larger keep context |
| Base detector | Local outlier factor or k-NN distance | Determines what kind of anomaly is found |
| Combination rule | Average, maximum or breadth-first | Controls how strongly single subspaces dominate |
| Score normalization | Rank or standardization | Makes scores from rounds comparable |
Combining anomaly scores across subspaces
The combination step decides how evidence from many subspaces becomes one ranking. Because raw scores from different subspaces have different scales, they should first be normalized, for example by converting them to ranks or z-scores. Without normalization, a single subspace with large distances can dominate the ensemble.
The original paper proposed two schemes. The breadth-first scheme interleaves the top-ranked points of every round, while the cumulative-sum scheme adds all scores. Later work added averaging, maximization and hybrids such as the average of maximum scores. Their behavior differs as follows.
| Combination rule | Strength | Weakness |
|---|---|---|
| Average | Low variance, robust ranking | Can dilute anomalies seen in few subspaces |
| Maximum | Highlights subspace-specific outliers | Sensitive to noisy rounds |
| Breadth-first | Gives each round a fair voice | Ignores score magnitudes |
| Average of maximum | Balances both effects | Requires grouping rounds into buckets |
Feature bagging compared with other ensemble detectors
Feature bagging belongs to the family of subspace outlier ensembles. It shares the random-projection idea with isolation forests but differs in that the base model is a full detector, not a single random split. The next table places it among neighboring methods in unsupervised anomaly detection.
| Method | Source of diversity | Typical strength |
|---|---|---|
| Feature bagging | Random feature subsets | Reduces noise from irrelevant dimensions |
| Isolation forest | Random features and split values | Very fast on large datasets |
| Extended isolation forest | Random hyperplane splits | Fewer axis-aligned artifacts |
| Single local outlier factor | None | Strong on low-dimensional local density |
| Rotated bagging | Random rotations of subspaces | Captures correlated feature patterns |
In comparative studies the method typically improves on its base detector when many features are irrelevant, but the gain shrinks when nearly all features carry signal. It is therefore a variance-reduction tool, not a replacement for good feature engineering.
Practical configuration and tooling
In Python, the PyOD library provides a FeatureBagging class that wraps any PyOD detector and exposes the number of estimators, the feature sampling range and the combination method. Practitioners should scale features before training, because distance-based base detectors are sensitive to units, and should set the contamination rate only when a threshold is needed.
| Situation | Recommendation | Reason |
|---|---|---|
| Many weak or noisy features | Use feature bagging with LOF | Subspaces filter irrelevant dimensions |
| Few, carefully engineered features | Use a single detector | Ensemble adds cost with little gain |
| Millions of records | Prefer isolation forest | Repeated LOF runs scale poorly |
| Anomalies tied to feature pairs | Use larger subspaces | Small subsets break the relationship |
Limitations and common mistakes
The main cost of feature bagging is computation: T rounds of a neighbor-based detector multiply runtime, and each round still scales roughly quadratically without indexing. Results also depend on random seeds, so reproducibility requires fixed seeds.
- Skipping normalization lets one subspace dominate the combined score.
- Too few estimators produce rankings that change from run to run.
- Subsets that are too small can split features whose joint values define the anomaly.
- Assuming interpretability: the combined score does not directly say which features caused the alert.
For explanation, analysts can inspect which subspaces produced the highest scores for a flagged point, which provides a useful starting point for anomaly explanation.
Evaluation also needs care. Because feature bagging is usually applied without labels, teams should validate it on a labeled holdout or injected anomalies and compare it with the plain base detector using ranking metrics such as average precision. If the ensemble does not beat the single detector on that check, the extra runtime is not justified, and simpler alternatives such as feature selection or dimensionality reduction should be tried first. Monitoring score stability across retraining runs is a practical way to detect configuration drift.
A non-technical view
Imagine a group of inspectors checking a warehouse. Each inspector looks at only a few properties of every box, such as weight, size or label. One sees nothing odd. Another notices a box that is far too light for its size.
Feature bagging works like that team. Each inspector gives every box a suspicion score. The scores are then pooled. A box that many inspectors find strange rises to the top. This makes the final judgment more stable than one inspector alone.
A concrete example
A payments team monitors merchant accounts described by 60 features, including refund ratios, transaction times, ticket sizes and device statistics. A single local outlier factor model flags many accounts that simply have unusual but harmless values in a few noisy features.
The team switches to feature bagging with 50 estimators, each using a random subset of 30 to 59 features, standardizes scores per round and combines them by averaging. Analysts then review the top 0.5 percent of accounts each week.
Compared with the single model, the ensemble ranking proves more stable between weekly runs, and analysts confirm a higher share of genuine fraud cases in the reviewed list, while the subspace scores help them see which feature groups raised each alert.