决策树案例(红酒)

# 决策树
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()
X=wine.data
Y=wine.target
df = pd.DataFrame(X)
df["class"] = Y

clf = tree.DecisionTreeClassifier(criterion="entropy")

x_train,x_test,y_train,y_test = train_test_split(X,Y,test_size=0.3)
clf.fit(x_train,y_train)
score = clf.score(x_test,y_test)
print(score)
import graphviz
feature_name = wine["feature_names"]
dot_data = tree.export_graphviz(clf,
    feature_names = feature_name,
    filled=True,
    rounded=True
)
graph=graphviz.Source(dot_data)
print(graph)

 

决策树案例(红酒)

上一篇:JVM工作原理-类成员的加载和执行过程


下一篇:[转]只有tcp6没有tcp问题