首页 > 解决方案 > 使用 joblib 腌制文件时出现 TypeError

问题描述

我正在开发用于异常检测的扩展隔离林。alogirthm 的 Gihub 链接在此处。训练后我无法腌制模型。我该如何解决这个错误。

iso_forest_model = iso.iForest(X , ntrees=100, sample_size=256, ExtensionLevel=1)

import joblib

joblib.dump(iso_forest_model, os.path.join(models_path,'extended_isolation_forest.pkl'), compress=9)

错误

--------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-36-6b85f8a16cb7> in <module>()
      6 
      7 import joblib
----> 8 joblib.dump(iso_forest_model, os.path.join(models_path,'extended_isolation_forest.pkl'), compress=9)

4 frames

/usr/local/lib/python3.7/dist-packages/joblib/numpy_pickle.py in dump(value, filename, compress, protocol, cache_size)
    475         with _write_fileobject(filename, compress=(compress_method,
    476                                                    compress_level)) as f:
--> 477             NumpyPickler(f, protocol=protocol).dump(value)
    478     elif is_filename:
    479         with open(filename, 'wb') as f:

/usr/lib/python3.7/pickle.py in dump(self, obj)
    435         if self.proto >= 4:
    436             self.framer.start_framing()
--> 437         self.save(obj)
    438         self.write(STOP)
    439         self.framer.end_framing()

/usr/local/lib/python3.7/dist-packages/joblib/numpy_pickle.py in save(self, obj)
    280             return
    281 
--> 282         return Pickler.save(self, obj)
    283 
    284 

/usr/lib/python3.7/pickle.py in save(self, obj, save_persistent_id)
    522             reduce = getattr(obj, "__reduce_ex__", None)
    523             if reduce is not None:
--> 524                 rv = reduce(self.proto)
    525             else:
    526                 reduce = getattr(obj, "__reduce__", None)

/usr/local/lib/python3.7/dist-packages/eif.cpython-37m-x86_64-linux-gnu.so in eif.iForest.__reduce_cython__()

TypeError: no default __reduce__ due to non-trivial __cinit__

标签: pythonpicklejoblibanomaly-detection

解决方案


推荐阅读