- Introduced by
- Liu, F. T., Ting, K. M., & Zhou, Z.-H. (iForest); SSL extensions by multiple authors
- Year
- 2008–2020s
- Type
- Ensemble anomaly detector with self-supervised pre-training
- Family
- Machine learning
What does it do?
Self-supervised Isolation Forest is a family of anomaly detectors that adds a self-supervised pre-training stage to the Isolation Forest algorithm.
A pretext task, solved without labels, is used to learn a feature representation, and isolation trees are then built on that representation rather than on the raw features. The cited sources document the Isolation Forest component; the self-supervised extension is not described in them.
The intuition behind the method
Isolation Forest flags points that can be separated from the rest with few random splits, because rare and different points need fewer splits to isolate. The self-supervised extension first trains an encoder on an auxiliary task that needs no labels, such as predicting a masked feature or distinguishing augmented copies of a sample. The intent is that isolation trees built in the learned space separate anomalies more easily than trees built on raw features. Whether this holds for a given dataset is an empirical question that the sources on this page do not settle.
History
Isolation Forest was introduced by Fei Tony Liu, Kai Ming Ting, and Zhi-Hua Zhou at ICDM 2008, where it was presented as a method that isolates anomalies rather than profiling normal points. The self-supervised variant has no originator cited on this page; it is described here as a family of approaches that adds a pre-training stage to Isolation Forest. Claims about its use in benchmarks would need sources that are not yet on this page.
When to use it
Consider this method for unlabelled tabular data with several continuous multivariate features, when plain Isolation Forest performs poorly and there is reason to think that the raw features are correlated, redundant, or need interactions to reveal outliers. The pre-training stage needs a reasonable pool of unlabelled data, but no cited source gives a minimum size. As rough practitioner guidance only, a few hundred samples is a lower bound and several thousand is more comfortable. Categorical features need an encoding step that the cited sources do not cover. Do not use the method on small datasets, when the raw features already separate anomalies, or when results must be explained directly in the original feature space. In those cases, plain Isolation Forest, which the original paper evaluates, is the simpler baseline to run first.
Limitations and considerations
- The pre-training stage adds a neural training step with its own hyperparameters. The linear-time property of Isolation Forest applies to the forest stage only, so total cost is higher, and the cited sources do not quantify it.
- Results depend on the pretext task. A task that does not match the structure of the data can produce a representation no better than the raw features.
- The encoder needs enough unlabelled data to learn useful structure. No cited source gives a minimum; the figures of a few hundred and several thousand samples are rough practitioner guidance.
- Scores are defined in the learned space, so they are harder to relate to the original features than the scores of plain Isolation Forest.
- The cited sources evaluate only plain Isolation Forest, so any benefit of the self-supervised stage has to be shown against that baseline on the target data.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Needs no anomaly labels for the pre-training stage, which suits settings where anomalies are rare or absent from the training data, a setting the original paper reports for plain Isolation Forest.
- Keeps the sub-sampled tree construction of the original Isolation Forest, which the original paper reports as linear in time with low memory requirements.
- The pretext task can be designed around known domain structure, for example by masking features that are expected to be related, so the learned representation reflects that structure.
- Produces a continuous anomaly score, so observations can be ranked and a threshold chosen afterwards.
Applications
- Unlabelled tabular monitoring data where anomalies are rare and training data are assumed to be mostly normal, the setting in which the original Isolation Forest was evaluated.
- Large tabular datasets where sub-sampling matters for runtime and memory, a setting the original paper reports for plain Isolation Forest.
- High-dimensional tabular data with many irrelevant attributes. The original paper reports that plain Isolation Forest works well in this setting; whether the representation stage adds to that is unverified and has to be tested against the plain baseline.
- Candidate domains such as transaction or network-log fraud and intrusion detection, sensor data, and tabular health records. The cited sources do not evaluate this variant in these domains.
How it works
How it works
The encoder is trained on unlabelled data using an auxiliary task. Candidate tasks include masked-feature reconstruction, prediction of a transformation applied to each row, and contrastive discrimination between augmented views of a sample. No anomaly labels are used, but the task determines what the encoder learns, so it should be chosen to match the feature structure of the data. Masked-feature reconstruction suits data whose columns are expected to be related, because the encoder must predict held-out columns from the rest. Contrastive augmentation suits data where a meaningful augmentation of a row can be defined. As practitioner guidance rather than a sourced rule, compare two candidate tasks by building a forest on each learned representation and checking which gives better AUC-PR on a held-out labelled set.
A neural encoder or other feature transformer is trained to minimise the pretext-task loss. Its hidden representation is intended to reflect the structure of the normal data, but how well it does so depends on the task chosen and on the volume of unlabelled data available. A basic check is that the pretext loss falls on held-out unlabelled rows. A representation that does not improve on the raw features in the baseline comparison should not be used.
The Isolation Forest procedure from the original paper is applied to the learned representations instead of the raw features. Each tree recursively splits the data on a randomly chosen feature and a random split value until points are isolated, and each tree is grown on a sub-sample of the training data. The original paper attributes its low time and memory cost to this sub-sampling. That cost applies to the forest stage; the cost of pre-training is not quantified in the cited sources and depends on the encoder.
Each point's anomaly score is based on its average path length across the trees: points isolated after few splits score high, and points that require many splits score low. The score is s(x,n) = 2^{-E[h(x)]/c(n)}, where E[h(x)] is the average path length and c(n) is the expected path length for a sample of size n, as in the original Isolation Forest.
Formula
s(x,n) = 2^{-E[h(x)]/c(n)}A contamination fraction or score threshold converts scores into normal and anomaly labels. The user has to choose this value. If a small labelled validation set exists it can guide the choice; otherwise the choice rests on an assumed anomaly rate. The sources on this page do not show that the learned representation changes the sensitivity of results to the threshold.
Common pitfalls
- Designing a pretext task that is trivially solved, or that encodes the anomaly signal itself, so that the learned features carry little information about normal structure.
- Pre-training and building the forest on the same data without a held-out check, which can give optimistic scores.
- Fixing the contamination fraction without tuning it; if a small labelled validation set exists, it can be used to choose the threshold.
- Reporting only AUROC. Because anomalies are rare, AUC-PR (precision-recall area) is often more informative, so both should be reported. This is general evaluation practice, not a finding from the cited sources.
Frequently asked questions
How does this differ from plain Isolation Forest?
Plain Isolation Forest builds trees directly on the raw features. The self-supervised variant first trains an encoder on a pretext task and then builds the trees on the learned representation. Whether this improves AUROC depends on the dataset, so the variant should be compared with a plain Isolation Forest baseline on the same data.
What pretext tasks are commonly used?
Common choices for tabular data include masked-feature reconstruction (predict held-out columns), rotation or permutation prediction (identify which permutation was applied to a row), and contrastive learning (pull augmented views of the same row together, push different rows apart). The best choice depends on the feature structure of the domain.
How much data is needed?
No cited source gives a minimum sample size for this variant. As rough practitioner guidance, the pre-training stage benefits from at least a few hundred samples, and ideally several thousand. With very small datasets the pretext task may overfit, and the learned features may be no better than the raw ones. In that regime plain Isolation Forest is usually the safer choice.
Is any labelled data required?
No labels are required for training. If a small labelled validation set is available, it can be used only to tune the contamination threshold and to select the pretext task; the core model trains fully unsupervised.
How do I evaluate the model?
Use AUROC and AUC-PR (precision-recall area) on a held-out labelled test set. Because anomalies are rare, AUC-PR is often more informative than AUROC. Compare against a plain Isolation Forest baseline to check that the self-supervised stage adds value.
Related methods
Sources
Liu, F. T., Ting, K. M., & Zhou, Z.-H. (2008). Isolation Forest. In Proceedings of the 8th IEEE International Conference on Data Mining (ICDM), pp. 413–422.
Open DOI referenceIsolation Forest. Wikipedia.
Open publication reference