Announcing ONNX Support in Isolation Forest
Originally published Updated 2 min read
Exporting standard Isolation Forest models trained in Spark for inference with a compatible ONNX runtime.

We added an ONNX converter so models trained with the Spark/Scala library can be scored without starting a Spark job.
The library, open-sourced in 2019, implements the algorithm introduced by Liu et al. in 2008; the original engineering article explains the algorithm and its use at LinkedIn.
Why ONNX
Before the converter, scoring a saved model required loading it into the library inside a Spark job. Export to ONNX made inference possible with a compatible ONNX runtime. A service or streaming consumer is a possible use; the exported graph’s operators must be supported by the selected runtime and backend.
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 converter’s input contract names the input features, a float32 matrix shaped [number of rows, number of training features]. Supply numeric features in the same order used during training. The Python example uses ONNX Runtime, as do the tests; the graph includes ai.onnx.ml tree-ensemble operators, so support in another runtime or provider needs checking.
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 on PyPI. Pin the converter to the same version as the isolation-forest release that trained your model, as the README specifies.
Comparing Spark and ONNX scores
The original converter tests compared benchmark AUROC with expected values. A later end-to-end integration test, present in the March 2026 revision, scores the same six-feature test data with the Spark model and exported ONNX graph, then compares their outputs. It passes float32 features to Python ONNX Runtime and asserts a maximum absolute score difference below 1e-5.
Scope
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
- Announcing ONNX Support in LinkedIn’s Open-Source Isolation Forest Library
- Detecting and preventing abuse on LinkedIn using isolation forests
- Open Source: Spark/Scala Isolation Forest Library
- isolation forest
- PR #53: converter implementation and Gradle integration for the Scala and Python modules
- isolation-forest-onnx