IsolationForest
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:
FR — Remplacement direct : même API que sklearn, changez l'import.
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
| Parameter | Type | Default | Description |
|---|---|---|---|
n_estimators | int | 100 | Number of isolation trees. |
max_samples | int | 256 | Max samples per tree. |
contamination | float | 0.1 | Expected fraction of outliers. |
seed | int | 42 | Random 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ètre | Type | Défaut | Description |
|---|---|---|---|
n_estimators | int | 100 | Nombre d'arbres d'isolation. |
max_samples | int | 256 | Max échantillons par arbre. |
contamination | float | 0.1 | Fraction attendue de valeurs aberrantes. |
seed | int | 42 | Graine 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]))