eminyous / fipe

https://arxiv.org/abs/2408.16167
MIT License
2 stars 1 forks source link

support for LightGBM #2

Open mglowacki100 opened 2 weeks ago

mglowacki100 commented 2 weeks ago

Hi, First of all cool package! Is it possible to add for support LightGBM? The issue is that LightGBM doesn't follow sklearn design pattern where e.g. random forest model is iterable and every element is sklearn decision tree, but LightGBM also exposes single trees, so it should be possible in principle.

import lightgbm as lgb

base = lgb.LGBMRegressor(n_estimators=...)
...
booster = base.booster_
model_json = booster.dump_model()
trees = model_json['tree_info']
trees[0]['tree_structure'] #first tree structure

{'split_index': 0,
 'split_feature': 2,
 'split_gain': 74.27210235595703,
 'threshold': 3644.0000000000005,
 'decision_type': '<=',
 'default_left': True,
 'missing_type': 'None',
 'internal_value': 1,
 'internal_weight': 0,
 'internal_count': 150,
 'left_child': {'split_index': 4,
  'split_feature': 1,
  'split_gain': 0.030392199754714966,
  'threshold': 5625.000000000001,
  'decision_type': '<=',
  'default_left': True,
  'missing_type': 'None',
  'internal_value': 0.901961,
  'internal_weight': 51,
  'internal_count': 51,
  'left_child': {'leaf_index': 0,
   'leaf_value': 0.905,
   'leaf_weight': 20,
   'leaf_count': 20},
  'right_child': {'leaf_index': 5,
   'leaf_value': 0.9,
   'leaf_weight': 31,
   'leaf_count': 31}}
....
eminyous commented 2 weeks ago

Hello,

First of all, thank you for your interest and your suggestion! This is an interesting extension of the package. We will be working on it very soon.

By the way, thank you again for the hints on how to export the LGBM structures.