决策树ID3算法之经典鸢尾花分类

from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
iris=load_iris()
modle=DecisionTreeClassifier(criterion='entropy')
from sklearn.model_selection import cross_val_predict
pred = cross_val_predict(estimator=modle, X=iris.data, y=iris.target, cv=5)
from sklearn.metrics import classification_report
report = classification_report(y_pred=pred, y_true=iris.target)
print(report)
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
iris=load_iris()
modle=DecisionTreeClassifier(criterion='entropy')
x_train,x_test,y_train,y_test=train_test_split(iris.data,iris.target)
modle.fit(x_train, y_train)
print(modle.score(x_test, y_test))

你可能感兴趣的:(ML)