决策树-鸢尾花-sklearn

决策树实战

直接看代码8

from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.cross_validation import train_test_split
from sklearn.metrics import accuracy_score

# 导入数据集
iris = load_iris()
# 特征
iris_feature = iris.data
# 分类标签
iris_label = iris.target

# 数据集划分
X_train,X_test,Y_train,Y_test = train_test_split(iris_feature,iris_label,test_size=0.3,random_state=42)

decisionTree_model = DecisionTreeClassifier()
# 模型训练
decisionTree_model.fit(X_train,Y_train)
predict = decisionTree_model.predict(X_test)

# 模型评估
print(accuracy_score(predict,Y_test))

你可能感兴趣的:(机器学习,Python,机器学习,决策树,Python)