Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

IsolationForest

Detector sklearn-compatible 🚨 Anomaly Detection

IsolationForest — anomaly detection via random partitioning trees. / IsolationForest — détection d'anomalies via arbres de partition aléatoire.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, numpy as np
X = np.random.randn(300, 4)
X[0] = [10, 10, 10, 10]
iso = sp.IsolationForest(n_estimators=100, contamination=0.05)
iso.fit(X)
print(iso.predict(X[:5]))
💡
EN — Drop-in replacement: sp.IsolationForest has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_isolation_forest — aliases: isolation_forest

Python class
sp.IsolationForest(n_estimators=100, max_samples=256, contamination=0.1, seed=42)
Constructor Parameters
ParameterTypeDefaultDescription
n_estimatorsint100Number of isolation trees.
max_samplesint256Max samples per tree.
contaminationfloat0.1Expected fraction of outliers.
seedint42Random seed.
Returns

JSON with labels (1 = inlier, −1 = outlier), scores.

Algorithm

$$s(x) = 2^{-E[h(x)]/c(n)}, \quad c(n) = 2H_{n-1} - \frac{2(n-1)}{n}$$

Example
import seraplot as sp, numpy as np
X = np.random.randn(300, 4)
X[0] = [10, 10, 10, 10]
iso = sp.IsolationForest(n_estimators=100, contamination=0.05)
iso.fit(X)
print(iso.predict(X[:5]))

Référence API

Nom de fonction JSON

ml_isolation_forest — alias : isolation_forest

Classe Python
sp.IsolationForest(n_estimators=100, max_samples=256, contamination=0.1, seed=42)
Paramètres du constructeur
ParamètreTypeDéfautDescription
n_estimatorsint100Nombre d'arbres d'isolation.
max_samplesint256Max échantillons par arbre.
contaminationfloat0.1Fraction attendue de valeurs aberrantes.
seedint42Graine aléatoire.
Retourne

JSON avec labels (1 = normal, −1 = anomalie), scores.

Algorithme

$$s(x) = 2^{-E[h(x)]/c(n)}, \quad c(n) = 2H_{n-1} - \frac{2(n-1)}{n}$$

Exemple
import seraplot as sp, numpy as np
X = np.random.randn(300, 4)
X[0] = [10, 10, 10, 10]
iso = sp.IsolationForest(n_estimators=100, contamination=0.05)
iso.fit(X)
print(iso.predict(X[:5]))