sklearn.tree.export_dict
See original GitHub issueCurrently, there are two options to get the decision tree representations: export_graphviz
and export_text
.
I would like to add export_dict
, which will output the decision as a nested dictionary.
While you can convert the graphviz representation using cli tools, it’s a bit unruly and is a weird workflow. When converting back, the nesting is also kind of weird, with /n
chars floating around.
The main utility for json/dict representations are
- That they’re far easier to work with for any front-end work.
- Working with a dict allows you to use the representation easily for any downstream tasks using the decision tree (that aren’t raw inference).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Export decision trees as dictionaries with `tree.export_dict`
Removes sklearn dependency for inference; It can be easily ported to other languages; It's very descriptive and good for educational purposes.
Read more >sklearn.tree.export_text — scikit-learn 1.2.0 documentation
The decision tree estimator to be exported. It can be an instance of DecisionTreeClassifier or DecisionTreeRegressor. feature_nameslist of str, default=None.
Read more >How to output decision tree data in sklearn - Stack Overflow
Having the data as a dictionary , DataFrame , array , etc. would make it easier to analyze, rather than just looking at...
Read more >Visualizing Decision Trees with Python (Scikit-learn, Graphviz ...
Export your model to a dot file. The code below code will work on any operating system as python generates the dot file...
Read more >Decision Tree visualization in Python | by Sourabh Potnis
from sklearn import tree ... from sklearn.tree.export import export_text ... To get the Decision tree as an ordered dictionary:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see
export_dict
as another way to serialize and inspect the tree without having to go through Python object. Going through the Python object can be a bit involved as demonstrated by our example. Other libraries has similar functions to serialized trees into something human readable such as: LightGBM’s model_to_string or XGBoost’s Model IO.I am overall +0.5 on adding this to sklearn. It has secondary benefit of making it a little easier to export the trees into another format. I suggest we wait to see other’s opinions before working on this.
Hi! I just like to add the description of the issue I just posted.
The main reason this feature would be useful for me is that I can easily port decision trees to other places. I already put some trees in web applications and microcontrollers. I would love to help if this would benefit the community as well.