Search code examples
nodesdecision-treesklearn-pandas

Is there a way to see the order of nodes categorizing data in decision trees when not allowed to install graphviz nor pydotplus?


I need to know the order of the nodes and the scores for each one, once I have ran the decision tree model. As I'm working in my office computer, the installations are very restricted and I'm not allowed to download graphviz nor pydotplus.

It doesn't matter that there is no graphic representation of the model; I just want to know the classification order/process the algorithm is using. I'm using sklearn.tree, sklearn.metrics, and sklearn.cross_validation.


Solution

  • You can make use of plot_tree of sklearn.tree module, I have illustrated an example below for your reference:

    from sklearn.datasets import load_iris
    from sklearn import tree
    clf = tree.DecisionTreeClassifier(random_state=0)
    iris = load_iris()
    
    clf = clf.fit(iris.data, iris.target)
    tree.plot_tree(clf, filled=True)
    

    Sample Output

    enter image description here