Sklearn 决策树与随机森林
通过sklearn中的红酒训练集测试并且画树 保存到了桌面的pdf文件中,目前还没有处理中文显示问题。 from sklearn import tree from sklearn . datasets import load_wine from sklearn . model_selection import train_test_split import pandas as pd wine = load_wine ( ) wine . data . shape wine . target pd . concat ( [ pd . DataFrame ( wine . data ) , pd . DataFrame ( wine . target ) ] , axis = 1 ) wine . feature_names wine . target_names Xtrain , Xtest , Ytrain , Ytest = train_test_split ( wine . data , wine . target , test_size = 0.3 ) clf = tree . DecisionTreeClassifier ( criterion = "entropy" ) clf = clf . fit ( Xtrain , Ytrain ) score = clf .