From ef991cf83dc3e20d13f00abf73c88560ff2599e0 Mon Sep 17 00:00:00 2001 From: Qiuyi He Date: Wed, 30 May 2018 14:37:36 +0800 Subject: [PATCH 1/2] correct is_regression --- eli5/lightgbm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eli5/lightgbm.py b/eli5/lightgbm.py index bfdf64e3..363f1ac5 100644 --- a/eli5/lightgbm.py +++ b/eli5/lightgbm.py @@ -170,7 +170,7 @@ def get_score_weights(_label_id): target_names=target_names, targets=targets, top_targets=top_targets, - is_regression=isinstance(lgb, lightgbm.LGBMRegressor), + is_regression=is_regression, is_multiclass=n_targets > 1, proba=proba, get_score_weights=get_score_weights, From 45379f50ebe37b929c4f6696c6a83c3b0985033e Mon Sep 17 00:00:00 2001 From: Qiuyi He Date: Wed, 30 May 2018 14:42:56 +0800 Subject: [PATCH 2/2] add explain_prediction test for regression booster --- tests/test_lightgbm.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_lightgbm.py b/tests/test_lightgbm.py index 35d45b61..c6d6d04b 100644 --- a/tests/test_lightgbm.py +++ b/tests/test_lightgbm.py @@ -20,6 +20,7 @@ ) from .test_sklearn_explain_prediction import ( assert_linear_regression_explained, + assert_trained_linear_regression_explained, test_explain_prediction_pandas as _check_explain_prediction_pandas, test_explain_clf_binary_iris as _check_binary_classifier, ) @@ -193,3 +194,13 @@ def test_explain_lightgbm_booster(boston_train): res = explain_weights(booster, feature_names=feature_names) for expl in format_as_all(res, booster): assert 'LSTAT' in expl + +def test_explain_prediction_reg_booster(boston_train): + X, y, feature_names = boston_train + booster = lightgbm.train( + params={'objective': 'regression', 'verbose_eval': -1}, + train_set=lightgbm.Dataset(X, label=y), + ) + assert_trained_linear_regression_explained( + X[0], feature_names, booster, explain_prediction, + reg_has_intercept=True)