Skip to content

Commit

Permalink
Merge pull request #219 from TeamHG-Memex/lightgbm-fix
Browse files Browse the repository at this point in the history
Fixed LightGBM explain_prediction
  • Loading branch information
kmike authored Jun 21, 2017
2 parents 54b31ac + 7a22ba4 commit 6ac969f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 45 deletions.
14 changes: 4 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,17 @@ matrix:
- python: 2.7
env: TOXENV=py27
- python: 2.7
env:
- TOXENV=py27-extra
- LIGHTGBM=1
env: TOXENV=py27-extra
- python: 3.5
env: TOXENV=py35
- python: 3.5
env:
- TOXENV=py35-extra
- LIGHTGBM=1
env: TOXENV=py35-extra
- python: 3.5
env: TOXENV=py35-nodeps
- python: 3.6
env: TOXENV=py36
- python: 3.6
env:
- TOXENV=py36-extra
- LIGHTGBM=1
env: TOXENV=py36-extra
- python: 3.5
env: TOXENV=mypy
- python: 3.5
Expand All @@ -41,11 +35,11 @@ addons:
- libatlas-base-dev
- liblapack-dev
- gfortran
- cmake

before_install:
- sudo apt-get -qq update
- if [[ "$TOXENV" != "py35-nodeps" ]]; then sudo apt-get install graphviz; fi
- if [[ "$LIGHTGBM" = 1 ]]; then bash _ci/install_lightgbm_linux.sh; export LIGHTGBM_CHECKOUT=LightGBM; fi

install:
- pip install -U pip tox codecov
Expand Down
7 changes: 0 additions & 7 deletions _ci/install_lightgbm_linux.sh

This file was deleted.

9 changes: 0 additions & 9 deletions _ci/install_py_lightgbm.sh

This file was deleted.

7 changes: 1 addition & 6 deletions _ci/runtests_extra.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/usr/bin/env bash
EXTRA_IGNORE=""
if [ -z "${LIGHTGBM_CHECKOUT}" ]; then
EXTRA_IGNORE="--ignore eli5/lightgbm.py"
fi

py.test --doctest-modules \
--ignore tests/test_lime.py \
--ignore tests/test_formatters.py \
Expand All @@ -12,5 +7,5 @@ py.test --doctest-modules \
--ignore tests/test_sklearn_explain_weights.py \
--ignore tests/test_sklearn_vectorizers.py \
--ignore tests/test_utils.py \
--ignore eli5/lightning.py ${EXTRA_IGNORE} \
--ignore eli5/lightning.py \
--cov=eli5 --cov-report=html --cov-report=term "$@"
8 changes: 6 additions & 2 deletions eli5/lightgbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,12 @@ def walk(tree):
left_value, left_count = walk(tree['left_child'])
right_value, right_count = walk(tree['right_child'])
count = left_count + right_count
tree['node_value'] = (left_value * left_count +
right_value * right_count) / count
if tree['split_gain'] <= 0:
assert left_value == right_value
tree['node_value'] = left_value
else:
tree['node_value'] = (left_value * left_count +
right_value * right_count) / count
return tree['node_value'], count

for tree in tree_info:
Expand Down
15 changes: 4 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
; this is a tox config for running ELI5 tests
; under all supported Python interpreters.

; To run LightGBM tests set LIGHTGBM_CHECKOUT
; env variable to a path to LightGBM checkout folder, e.g.
; LIGHTGBM_CHECKOUT=~/source/LightGBM tox -e py35-extra.
;
; LightGBM library itself should be already built, as described at
; https://github.com/Microsoft/LightGBM/wiki/Installation-Guide
; Building LighGBM may require additional system-level dependencies
; (e.g. cmake); please consult with
; https://github.com/Microsoft/LightGBM/tree/master/python-package#lightgbm-python-package.

[tox]
envlist = py27,py34,py35,py35-nodeps,mypy,py35-extra,py27-extra,py36,py36-extra
Expand All @@ -22,7 +19,6 @@ deps=


[testenv]
passenv = LIGHTGBM_CHECKOUT
whitelist_externals = /bin/bash
deps=
{[base]deps}
Expand Down Expand Up @@ -52,13 +48,10 @@ basepython=python3.5
deps=
{[testenv]deps}
xgboost
lightgbm

commands=
pip install -e .

; install LighGBM Python wrapper
bash ./_ci/install_py_lightgbm.sh

; run tests for extra dependencies
bash _ci/runtests_extra.sh {posargs: eli5 tests}

Expand Down

0 comments on commit 6ac969f

Please sign in to comment.