Announcing ONNX Support in Isolation Forest

Exporting standard Isolation Forest models trained in Spark for inference with a compatible ONNX runtime.

ONNX support architecture for LinkedIn isolation forest

We added an ONNX converter so models trained with the Spark/Scala library can be scored without starting a Spark job.

The library was open-sourced in 2019 and implements the Isolation Forest algorithm introduced by Liu et al. in 2008. Its original application at LinkedIn was automation detection.

How the Converter Works

The converter was added as the Python module isolation-forest-onnx in PR #53, merged September 3, 2024. It reads the library’s saved-model layout: model_file_path points to the Avro data file and metadata_file_path to the metadata file. It then emits an ONNX graph:

from isolationforestonnx.isolation_forest_converter import IsolationForestConverter

converter = IsolationForestConverter(model_file_path, metadata_file_path)
converter.convert_and_save('isolation_forest.onnx')

The exported model takes an input named features: a float32 matrix with one row per observation and one column per training feature. Feature order must match the training data. The example below uses ONNX Runtime, which is also used in the tests. Other runtimes must support the graph’s ai.onnx.ml tree-ensemble operators.

import numpy as np
from onnxruntime import InferenceSession

session = InferenceSession('isolation_forest.onnx')
scores = session.run(None, {'features': features.astype(np.float32)})[0]

The package is available on PyPI. Use the converter version matching the isolation-forest release that trained the model.

Comparing Spark and ONNX scores

The original converter tests compared benchmark AUROC with expected values. The March 2026 end-to-end integration test compares Spark and ONNX scores for the same six-feature dataset. It supplies float32 features to ONNX Runtime and requires a maximum absolute score difference below 1e-5.

Extended Isolation Forest

Update (2026): ONNX conversion covers the standard IsolationForestModel. The Extended Isolation Forest models added to the library in 2026 use hyperplane splits that do not map onto the axis-aligned tree representation the converter targets, so EIF scoring stays in Spark for now.

Resources