Skip to content

Instantly share code, notes, and snippets.

@MaxHalford
Created October 15, 2019 08:37
Show Gist options
  • Save MaxHalford/78df9e8d209a6487ac04b87dd254534a to your computer and use it in GitHub Desktop.
Save MaxHalford/78df9e8d209a6487ac04b87dd254534a to your computer and use it in GitHub Desktop.
LightGBM tree outputs
import lightgbm as lgb
from sklearn import datasets
from sklearn import model_selection
X, y = datasets.load_boston(return_X_y=True)
X_fit, X_val, y_fit, y_val
model = lgb.LGBMRegressor()
model.fit(X_fit, y_fit)
y_pred = model.predict(X_val)
y_pred_all = np.array([
[
model._Booster.get_leaf_output(tree_id, leaf_id)
for tree_id, leaf_id in enumerate(indexes)
]
for indexes in leaf_ids
])
assert sum(y_pred_all[0]) == y_pred[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment