通过读取csv文件显示树

时间:2019-03-12 12:04:15

标签: python

嗨,我将这段代码与jupyter一起使用,但我想为我自己的数据german_credit.csv显示树,而不是爱尔兰语,我尝试read_csv所做的更改是什么

import sklearn.datasets as datasets
import pandas as pd
iris=datasets.load_iris()
df=pd.DataFrame(iris.data, columns=iris.feature_names)
y=iris.target

from sklearn.tree import DecisionTreeClassifier
dtree=DecisionTreeClassifier()
dtree.fit(df,y)
from sklearn.externals.six import StringIO  
from IPython.display import Image  
from sklearn.tree import export_graphviz
import pydotplus
dot_data = StringIO()
export_graphviz(dtree, out_file=dot_data,  
                filled=True, rounded=True,
                special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
Image(graph.create_png())

1 个答案:

答案 0 :(得分:0)

df=pd.DataFrame(iris.data, columns=iris.feature_names)

将其更改为df=pd.read_csv('D://your_path_to_file//germen_credit.csv')