Is there a way to get tree data as a list with the LightGBM Classifier

784 Views Asked by At

In random forest type models, there is usually an attribute like "estimators" which returns all the tree split as a list of lists. I can't seem find something similar with lightgbm. The closest I can come is lgb.plot_tree which gives a nice visualization of a single tree. But I would like to use the data shown in the visualization in variables.

How can I get at this data?

1

There are 1 best solutions below

0
josemz On

There's not something exactly the same in LightGBM. But you could use the dump_model or trees_to_dataframe methods of the booster_ attribute of the scikit-learn estimator, i.e.

clf = lgb.LGBMClassifier().fit(X, y)
clf.booster_.dump_model()
clf.booster_.trees_to_dataframe()