'DecisionTreeClassifier' object has no attribute 'export_graphviz'

14,439

That's because you used somewhere tree name as name for DecisionTreeClassifier. Use another name there.

Share:
14,439

Related videos on Youtube

Wei Jiang
Author by

Wei Jiang

Updated on September 16, 2022

Comments

  • Wei Jiang
    Wei Jiang over 1 year

    I'm using python sklearn RandomForestClassifier and try to export decisiontrees.

    The basic code is as following:

    from sklearn import tree
    
    with open(dot_file_name, 'w') as my_file:
        tree.export_graphviz(tree1, out_file = my_file,feature_names = feature_names)
    

    After run the python script, following error show up: Attribute error: 'DecisionTreeClassifier' object has no attribute 'export_graphviz'

    I'm using python 2.7. Is it because of the version of python? Do I have to use python 3.0?