Feature bagging · anomaly detection

On this page 7

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.

ParameterTypical settingEffect
Number of estimators10 to 100More rounds stabilize scores but cost time
Subspace sizeBetween d/2 and d minus 1 featuresSmaller subsets add diversity, larger keep context
Base detectorLocal outlier factor or k-NN distanceDetermines what kind of anomaly is found
Combination ruleAverage, maximum or breadth-firstControls how strongly single subspaces dominate
Score normalizationRank or standardizationMakes scores from rounds comparable
Main parameters and typical settings

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 ruleStrengthWeakness
AverageLow variance, robust rankingCan dilute anomalies seen in few subspaces
MaximumHighlights subspace-specific outliersSensitive to noisy rounds
Breadth-firstGives each round a fair voiceIgnores score magnitudes
Average of maximumBalances both effectsRequires grouping rounds into buckets
Score combination rules compared

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.

MethodSource of diversityTypical strength
Feature baggingRandom feature subsetsReduces noise from irrelevant dimensions
Isolation forestRandom features and split valuesVery fast on large datasets
Extended isolation forestRandom hyperplane splitsFewer axis-aligned artifacts
Single local outlier factorNoneStrong on low-dimensional local density
Rotated baggingRandom rotations of subspacesCaptures correlated feature patterns
Position among related anomaly detection methods

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.

SituationRecommendationReason
Many weak or noisy featuresUse feature bagging with LOFSubspaces filter irrelevant dimensions
Few, carefully engineered featuresUse a single detectorEnsemble adds cost with little gain
Millions of recordsPrefer isolation forestRepeated LOF runs scale poorly
Anomalies tied to feature pairsUse larger subspacesSmall subsets break the relationship
Decision guide for typical situations

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.