写一个决策树的python代码
时间: 2023-03-11 13:53:53 浏览: 119
决策树python代码
import numpy as np
from sklearn import tree# [Height, Weight, Shoe Size]
X = [[181, 80, 44], [177, 70, 43], [160, 60, 38], [154, 54, 37], [166, 65, 40],
[190, 90, 47], [175, 64, 39],
[177, 70, 40], [159, 55, 37], [171, 75, 42], [181, 85, 43]]Y = ['male', 'male', 'female', 'female', 'male', 'male', 'female', 'female',
'female', 'male', 'male']# Create a Decision Tree Classifier
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X,Y)prediction = clf.predict([[190, 70, 43]])print(prediction)
阅读全文