Skip to content

Commit

Permalink
fixed deserialization logic for mimic explainer with older versions o…
Browse files Browse the repository at this point in the history
…f lightgbm (#124)
  • Loading branch information
imatiach-msft authored Dec 5, 2019
1 parent 92ed4c4 commit b14955a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/interpret_community/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class LightGBMSerializationConstants(object):
LOGGER = '_logger'
MODEL_STR = 'model_str'
MULTICLASS = 'multiclass'
REGRESSION = 'regression'
TREE_EXPLAINER = '_tree_explainer'
OBJECTIVE = 'objective'

Expand Down
10 changes: 8 additions & 2 deletions python/interpret_community/mimic/models/lightgbm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,19 @@ def _load(properties):
# https://github.com/Microsoft/LightGBM/issues/1942
# https://github.com/Microsoft/LightGBM/issues/1217
booster_args = {LightGBMSerializationConstants.MODEL_STR: value}
is_multiclass = json.loads(properties[LightGBMSerializationConstants.MULTICLASS])
if is_multiclass:
objective = LightGBMSerializationConstants.MULTICLASS
else:
objective = LightGBMSerializationConstants.REGRESSION
if LightGBMSerializationConstants.MODEL_STR in inspect.getargspec(Booster).args:
extras = {LightGBMSerializationConstants.OBJECTIVE: LightGBMSerializationConstants.MULTICLASS}
extras = {LightGBMSerializationConstants.OBJECTIVE: objective}
lgbm_booster = Booster(**booster_args, params=extras)
else:
# For backwards compatibility with older versions of lightgbm
booster_args[LightGBMSerializationConstants.OBJECTIVE] = objective
lgbm_booster = Booster(params=booster_args)
if json.loads(properties[LightGBMSerializationConstants.MULTICLASS]):
if is_multiclass:
new_lgbm = LGBMClassifier()
new_lgbm._Booster = lgbm_booster
new_lgbm._n_classes = _n_classes
Expand Down

0 comments on commit b14955a

Please sign in to comment.