Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lightgbm.booster support #270

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update booster is_regression
  • Loading branch information
qh582 authored May 31, 2018
commit 0a488e391baf93b3030768a1c976793e271706e6
5 changes: 2 additions & 3 deletions docs/source/libraries/lightgbm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ LightGBM

LightGBM_ is a fast Gradient Boosting framework; it provides a Python
interface. eli5 supports :func:`eli5.explain_weights`
and :func:`eli5.explain_prediction` for ``lightgbm.LGBMClassifer``, ``lightgbm.LGBMRegressor`` and ``lightgbm.Booster`` estimators. It is tested against LightGBM
master branch.
and :func:`eli5.explain_prediction` for ``lightgbm.LGBMClassifer``, ``lightgbm.LGBMRegressor`` and ``lightgbm.Booster`` estimators.

.. _LightGBM: https://github.com/Microsoft/LightGBM

Expand All @@ -22,7 +21,7 @@ arguments for LGBMClassifier , LGBMClassifier and lightgbm.Booster:
- 'weight' - the same as 'split', for better compatibility with
:ref:`library-xgboost`.

``target_names`` and ``target`` arguments are ignored.
``target_names`` arguement is ignored for ``lightgbm.LGBMClassifer`` / ``lightgbm.LGBMRegressor``, but used for ``lightgbm.Booster``. ``target`` argument is ignored.
Copy link
Contributor

@kmike kmike Nov 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``target_names`` arguement is ignored for ``lightgbm.LGBMClassifer`` / ``lightgbm.LGBMRegressor``, but used for ``lightgbm.Booster``. ``target`` argument is ignored.
``target_names`` argument is ignored for ``lightgbm.LGBMClassifer`` / ``lightgbm.LGBMRegressor``, but used for ``lightgbm.Booster``. ``targets`` argument is ignored.


.. note::
Top-level :func:`eli5.explain_weights` calls are dispatched
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lightgbm.Booster should be mentioned here as well.

Expand Down
11 changes: 7 additions & 4 deletions eli5/lightgbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def explain_weights_lightgbm(lgb,
``top``, ``feature_names``,
``feature_re`` and ``feature_filter`` parameters.

``target_names`` and ``targets`` parameters are ignored.
``target_names`` arguement is ignored for ``lightgbm.LGBMClassifer`` / ``lightgbm.LGBMRegressor``,
but used for ``lightgbm.Booster``.
``target`` argument is ignored.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``target`` argument is ignored.
``targets`` argument is ignored.


Parameters
----------
Expand Down Expand Up @@ -123,12 +125,13 @@ def explain_prediction_lightgbm(
prediction = lgb.predict(X)
n_targets = prediction.shape[-1]
if is_regression is None and target_names is None:
# When n_targets is 1, this can be classification too,
# but it's safer to assume regression.
# When n_targets is 1, this can be classification too.
# It's safer to assume regression in this case,
# unless users set it as a classification problem by assigning 'target_names' input [0,1] etc.
# If n_targets > 1, it must be classification.
is_regression = n_targets == 1
elif is_regression is None:
is_regression = len(target_names) == 1
is_regression = len(target_names) == 1 and n_targets == 1

if is_regression:
proba = None
Expand Down