-
Notifications
You must be signed in to change notification settings - Fork 334
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
base: master
Are you sure you want to change the base?
Conversation
mainly followed the logic of xgboost.booster support
add lightgbm.booster support
Codecov Report
@@ Coverage Diff @@
## master #270 +/- ##
==========================================
- Coverage 97.22% 97.22% -0.01%
==========================================
Files 44 44
Lines 2815 2845 +30
Branches 536 545 +9
==========================================
+ Hits 2737 2766 +29
Misses 41 41
- Partials 37 38 +1
|
eli5/lightgbm.py
Outdated
proba=proba, | ||
get_score_weights=get_score_weights, | ||
) | ||
|
||
|
||
def _check_booster_args(lgb, is_regression=None): | ||
# type: (Any, bool) -> Tuple[Booster, bool] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope something like # type: (Any, bool) -> Tuple[lightgbm.Booster, bool]
and adding Tuple
and Any
to typing
imports at the top should fix the build (https://travis-ci.org/TeamHG-Memex/eli5/jobs/385021206#L764-L766). To check locally, you can try installing mypy==0.550
and running mypy --check-untyped-defs eli5
Thanks for the PR @qh582 , at first sight it looks good 👍 |
@lopuhin Thanks for review and suggestion. solved it. I am doing the |
add explain_prediction test for regression booster
fix bug of using multiclass booster to fit binary case
@lopuhin could you please check it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding test done
@qh582 looks good! Would you mind updating a few notes in docs, mentioning this new feature? |
* Update overview.rst * Update README.rst * Update lightgbm.rst
* Update overview.rst * Update README.rst * Update lightgbm.rst
@kmike I think this is ready, please check :) |
("objective" starts with "reg") | ||
and False for a classification problem. | ||
If not set, regression is assumed for a single target estimator | ||
and proba will not be shown unless the ``target_names`` is defined as a list with length of two. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to contradict a note above (line 25, "target_names is ignored") - does the note about target_names apply only to classifier/regressor, but not for Booster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for a single target estimater, booster cannot recognize wheather it is a regression problem or not. We assume it is regression in default, unless users set it as a classification problem by assigning 'target names' input [0,1] etc. Only in this case 'target names' is used. Should I remove " target names is ignored" to prevent confusion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target names is still ignored for classifier/regressor, right? I think it makes sense to clarify it - just say that it is ignored for LGBMClassifier / LGBMRegressor, but used for lightgbm.Booster.
"is defined as a list with length of two" - sohuld it be 2 elements, or 2+ is also supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, for single target booster, only 1+ elements target_name point booster to classification. Otherwise, this booster is regression . there is risk user assign wrong number of elements like 3, but not sure how eli5 will raise error. 2+ should not support here.
docs/source/libraries/lightgbm.rst
Outdated
and :func:`eli5.explain_prediction` for ``lightgbm.LGBMClassifer`` | ||
and ``lightgbm.LGBMRegressor`` estimators. | ||
and :func:`eli5.explain_prediction` for ``lightgbm.LGBMClassifer``, ``lightgbm.LGBMRegressor`` and ``lightgbm.Booster`` estimators. It is tested against LightGBM | ||
master branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"It is tested against LightGBM master branch." is removed in 63e9918, sorry for the confusion. It shouldn't be re-added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, I will remove that line in next commit
@kmike Hope the new commit help. My previous piece of code is not strict enough. |
It's been two month, could someone tell me why this merge hasn't been closed already? I really need this. |
I think PR is in great shape and we just need to check it again and merge it, hope to find time for it soonish, sorry for delay. |
|
||
.. _LightGBM: https://github.com/Microsoft/LightGBM | ||
|
||
:func:`eli5.explain_weights` uses feature importances. Additional | ||
arguments for LGBMClassifier and LGBMClassifier: | ||
arguments for LGBMClassifier , LGBMClassifier and lightgbm.Booster: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a nitpick: extra whitespace before comma
@@ -22,7 +21,7 @@ arguments for LGBMClassifier and LGBMClassifier: | |||
- '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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``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. |
|
||
.. _LightGBM: https://github.com/Microsoft/LightGBM | ||
|
||
:func:`eli5.explain_weights` uses feature importances. Additional | ||
arguments for LGBMClassifier and LGBMClassifier: | ||
arguments for LGBMClassifier , LGBMClassifier and lightgbm.Booster: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments for LGBMClassifier , LGBMClassifier and lightgbm.Booster: | |
arguments for LGBMClassifier, LGBMClassifier and lightgbm.Booster: |
@@ -22,7 +21,7 @@ arguments for LGBMClassifier and LGBMClassifier: | |||
- '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. | |||
|
|||
.. note:: | |||
Top-level :func:`eli5.explain_weights` calls are dispatched |
There was a problem hiding this comment.
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.
@@ -50,6 +49,14 @@ for ``lightgbm.LGBMClassifer`` and ``lightgbm.LGBMRegressor``: | |||
estimator. Set it to True if you're passing ``vec``, | |||
but ``doc`` is already vectorized. | |||
|
|||
``lightgbm.Booster`` estimator accepts one more optional argument: | |||
|
|||
* ``is_regression`` - True if solving a regression problem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this parameter supported? It is not an argument of explain_prediction_lightgbm.
@@ -31,7 +31,7 @@ following machine learning frameworks and packages: | |||
of XGBClassifier, XGBRegressor and xgboost.Booster. | |||
|
|||
* :ref:`library-lightgbm` - show feature importances and explain predictions | |||
of LGBMClassifier and LGBMRegressor. | |||
of LGBMClassifier , LGBMRegressor and lightgbm.Booster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of LGBMClassifier , LGBMRegressor and lightgbm.Booster. | |
of LGBMClassifier, LGBMRegressor and lightgbm.Booster. |
``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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``target`` argument is ignored. | |
``targets`` argument is ignored. |
Any plans about merging it, @lopuhin? |
Thanks you! This were merged in eli5-org/eli5#7 and released to PyPI with v0.11 |
mainly followed the logic of xgboost.booster support