Is there a way to output decision tree data, eg as a dictionary? I'm aware of sklearn.tree.export_graphviz
, which is a great visual, but I was wondering if there was a way to output, say, this:
as this:
{0: 'samples': 100.0%, 'value': [0.53, 0.47],
1: 'samples': 72.6%, 'value': [0.61, 0.39],
2: 'samples': 27.4%, 'value': [0.38, 0.62]}
Having the data as a dictionary
, DataFrame
, array
, etc. would make it easier to analyze, rather than just looking at some colored boxes. I've looked through the sklearn
documentation but couldn't find anything.
Thanks
It looks like there is an implementation for this here . After playing with it, I think one of the limiting factors is the depth of a dict like this. Remember that a tree like this isn't:
{node1:[data],
node2:[data],
node3:[data],
etc}
It's more like:
{node1:[data],
sub-node1:{
sub-sub-node1:{
sub-sub-sub-node1:[data],sub-sub-sub-node2:[data],...}
sub-sub-node2:{
sub-sub-sub-node1:[data],sub-sub-sub-node2:[data],...}
etc}
sub-node2:{etc}
}
Which can quickly get out of hand if you have a tree with high (or None
) max_depth
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.