question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converter for pyod.models.iforest.IForest

See original GitHub issue

Is it possible to get converter for pyod anomaly detection models? https://pyod.readthedocs.io/en/latest/_modules/pyod/models/iforest.html

pyod Iforest is a Wrapper of scikit-learn Isolation Forest with more functionalities.

Traceback (most recent call last):

  File "<ipython-input-91-f753e8bf7b2f>", line 1, in <module>
    IFOnnx_model = convert_sklearn(model1, initial_types=initial_type)

  File "C:\Users\pl\Anaconda3\lib\site-packages\onnxmltools\convert\main.py", line 66, in convert_sklearn
    custom_conversion_functions, custom_shape_calculators)

  File "C:\Users\pl\Anaconda3\lib\site-packages\skl2onnx\convert.py", line 150, in convert_sklearn
    topology.compile()

  File "C:\Users\pl\Anaconda3\lib\site-packages\skl2onnx\common\_topology.py", line 903, in compile
    self._infer_all_types()

  File "C:\Users\pl\Anaconda3\lib\site-packages\skl2onnx\common\_topology.py", line 756, in _infer_all_types
    operator.infer_types()

  File "C:\Users\pl\Anaconda3\lib\site-packages\skl2onnx\common\_topology.py", line 215, in infer_types
    type(self.raw_operator)))

MissingShapeCalculator: Unable to find a shape calculator for type '<class 'pyod.models.iforest.IForest'>'.
It usually means the pipeline being converted contains a
transformer or a predictor with no corresponding converter
implemented in sklearn-onnx. If the converted is implemented
in another library, you need to register
the converted so that it can be used by sklearn-onnx (function
update_registered_converter). If the model is not yet covered
by sklearn-onnx, you may raise an issue to
https://github.com/onnx/sklearn-onnx/issues
to get the converter implemented or even contribute to the
project. If the model is a custom model, a new converter must
be implemented. Examples can be found in the gallery.

sample code for IForest

import pandas as pd
from pyod.models.iforest import IForest
from sklearn.preprocessing import MinMaxScaler

data1 = {'First':  [500,500,400,100,200,300,100],
         'Second': ['a','b','a','b','a','b','c'],
         }
df1 = pd.DataFrame(data1,columns=['First','Second'])
dumdf1 = pd.get_dummies(df1) 
scaler = MinMaxScaler()
scaler.partial_fit(dumdf1)
sc_data = scaler.transform(dumdf1)
model1 = IForest(n_estimators=10,
               bootstrap=True,
               behaviour='new',
               contamination=0.1,
               random_state=np.random.RandomState(42),
               verbose=1,
               n_jobs=-1).fit(sc_data)
feature_names2 = dumdf1.columns

from onnxmltools.convert.common.data_types import FloatTensorType
from onnxmltools import convert_sklearn

initial_type = [('float_input', FloatTensorType([None, len(feature_names2)]))]
IFOnnx_model = convert_sklearn(model1, initial_types=initial_type)

Thanks in advance

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
xaduprecommented, Aug 5, 2021

Thanks for letting me know. I’ll close the issue. Feel free to reopen it if something fails again.

1reaction
xaduprecommented, Jul 15, 2021

There are many extensions to scikit-learn and sklearn-onnx cannot support all of them. You may follow the tutorial to implement a new converter Implement a new converter. I could also add an example to the documentation to show how to do it. What do you prefer?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Converter for pyod.models.iforest.IForest - ONNX
It implements a custom converter for model pyod.models.iforest.IForest. This example uses Implement a new converter as a start. Trains a model.
Read more >
All Models - pyod 1.0.7 documentation
simply use Min-max conversion to linearly transform the outlier scores into the range of [0,1]. The model must be fitted ... class pyod.models.iforest....
Read more >
Write converters for other libraries — sklearn-onnx 1.13 ...
It implements a mechanism to register converters from other libraries. Converters for models from other ... Converter for pyod.models.iforest.IForest.
Read more >
pyod Documentation - Read the Docs
IForest (n_estimators=200)]. # decide the number of parallel process, and the combination method. # then clf can be used as any outlier detection...
Read more >
How to use the pyod.models.feature_bagging.FeatureBagging ...
To help you get started, we've selected a few pyod.models.feature_bagging. ... 'Isolation Forest': IForest(contamination=outliers_fraction), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found