Skip to content

Commit

Permalink
Use public API of IsolationForest (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 authored Aug 29, 2024
1 parent 4d8430e commit bf9c75a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion python/treelite/sklearn/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,17 @@ def import_model(sklearn_model):
----
For :py:class:`~sklearn.ensemble.IsolationForest`, the loaded model will calculate the outlier
score using the standardized ratio as proposed in the original reference,
which matches with :py:meth:`~sklearn.ensemble.IsolationForest._compute_chunked_score_samples`
which matches with :py:meth:`~sklearn.ensemble.IsolationForest.score_samples`
but is a bit different from :py:meth:`~sklearn.ensemble.IsolationForest.decision_function`.
More precisely, the following relation holds:
.. code-block:: python
treelite.gtil.predict(tl_model, X) == -clf.score_samples(X)
# clf is an IsolationForest
# tl_model is a Treelite representation of clf
Parameters
----------
sklearn_model : object of type \
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_sklearn_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_skl_converter_iforest(dataset):
random_state=0,
)
clf.fit(X)
expected_pred = clf._compute_chunked_score_samples(X) # pylint: disable=W0212
expected_pred = -clf.score_samples(X)
expected_pred = expected_pred.reshape((-1, 1, 1))

tl_model = treelite.sklearn.import_model(clf)
Expand Down

0 comments on commit bf9c75a

Please sign in to comment.