Closed zds0 closed 3 years ago
Thanks for the bug report. Yes, that small change would solve the issue.
This wasn't quite the complete solution. There's a related (and perhaps uncommon) scenario that encounters a similar bug.
When you import a saved model (extending on the example above)
iso_imp = IsolationForest.import_model('test_isolationforest', use_cpp=True)
and then re-export that same model object
iso_imp.export_model('test_isolationforest2', use_cpp=True)
the following error is thrown
TypeError Traceback (most recent call last)
<ipython-input-14-a78373200393> in <module>
----> 1 iso_imp.export_model('test_isolationforest2', use_cpp=True)
isotree/__init__.py in export_model(self, file, use_cpp)
2128 """
2129 assert self.is_fitted_
-> 2130 metadata = self._export_metadata()
2131 with open(file + ".metadata", "w") as of:
2132 json.dump(metadata, of, indent=4)
isotree/__init__.py in _export_metadata(self)
2363 "cat_levels" : [list(m) for m in self._cat_mapping],
2364 "categ_cols" : [] if self.categ_cols is None else list(self.categ_cols),
-> 2365 "categ_max" : list(self._cat_max_lev)
2366 }
2367
TypeError: 'NoneType' object is not iterable
I was able to resolve by replacing like 2365 with
"categ_max" : [] if self._cat_max_lev is None else list(self._cat_max_lev)
But again I'll leave it to you to decide if this is functionality you wish to support and to determine if this is the correct solution (I think there are a few different ways of handling).
Thanks for the great work on this research and this library!
Thanks again. That should solve it, but I've added a couple extra checks just in case.
Models without
categ_cols
(i.e. models fit on dataframes with numeric columns only) fail to export.To reproduce, run the python example in the README
and then try to call
export_model
the following error is thrown
I was able to resolve this by replacing line 2348 (in the
data_info
dict withinexport_metadata()
) with the following:However, I'm unsure if this if the complete/proper solution. Thanks.