Qu

isolation_forest

Builtin index · Statistics & ML

result = isolation_forest(X, [n_trees=100], [max_samples=256], [contamination=], [seed=])

Input: X, n_trees, max_samples, contamination, seed · Output: result

What it is

Anomaly detection on an N-row, D-column matrix X by random partitioning (Liu, Ting & Zhou 2008): grows n_trees (integer, default 100) trees, each on its own subsample of max_samples rows (integer, default 256, capped at N) drawn without replacement, splitting on a uniformly random feature at a uniformly random cut point, and measures how few cuts it takes to isolate each row. It does not model "normal" and flag the misfits — a point in a sparse region is simply cut off sooner. contamination (optional number strictly between 0 and 1) is the expected fraction of anomalies and sets .threshold to the matching score quantile; without it the threshold is the paper's conventional 0.5. An optional integer seed= fixes every draw.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = isolation_forest(X, [n_trees=100], [max_samples=256], [contamination=], [seed=])
X matrixAnomaly detection on an N-row, D-column matrix X by random partitioning (Liu, Ting & Zhou 2008): grows n_trees (integer, default 100) trees, each on its own subsample of max_samples rows (integer, default 256, capped at N) drawn without replacement, splitting on a uniformly random feature at a uniformly random cut point, and measures how few cuts it takes to isolate each row.
n_trees matrix, optional (default 100)Anomaly detection on an N-row, D-column matrix X by random partitioning (Liu, Ting & Zhou 2008): grows n_trees (integer, default 100) trees, each on its own subsample of max_samples rows (integer, default 256, capped at N) drawn without replacement, splitting on a uniformly random feature at a uniformly random cut point, and measures how few cuts it takes to isolate each row.
max_samples matrix, optional (default 256)Anomaly detection on an N-row, D-column matrix X by random partitioning (Liu, Ting & Zhou 2008): grows n_trees (integer, default 100) trees, each on its own subsample of max_samples rows (integer, default 256, capped at N) drawn without replacement, splitting on a uniformly random feature at a uniformly random cut point, and measures how few cuts it takes to isolate each row.
contamination number, optionalcontamination (optional number strictly between 0 and 1) is the expected fraction of anomalies and sets .threshold to the matching score quantile.
seed optionalAn optional integer seed= fixes every draw.
scores —length-N, on (0, 1), higher is more anomalous
labels —length-N, 1 anomalous / 0 normal
Returns a fitted model Record with fields scores (length-N, on (0, 1), higher is more anomalous), labels (length-N, 1 anomalous / 0 normal), threshold, n_trees, max_samples, n_features, and the stored forest (nodes, roots). .predict(Xnew) gives the same score for M rows the forest was never fit on. Added in v0.3.0.

Examples

No documentation example calls this form yet. The Statistics & ML chapter is where one belongs.