Created
October 15, 2019 08:37
-
-
Save MaxHalford/78df9e8d209a6487ac04b87dd254534a to your computer and use it in GitHub Desktop.
LightGBM tree outputs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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