W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
demo_python_ml_dtree_predict_2.py:
import pandas from sklearn import tree from sklearn.tree import DecisionTreeClassifier df = pandas.read_csv("shows.csv") d = {'UK': 0, 'USA': 1, 'N': 2} df['Nationality'] = df['Nationality'].map(d) d = {'YES': 1, 'NO': 0} df['Go'] = df['Go'].map(d) features = ['Age', 'Experience', 'Rank', 'Nationality'] X = df[features] y = df['Go'] dtree = DecisionTreeClassifier() dtree = dtree.fit(X, y) print(dtree.predict([[40, 10, 6, 1]])) print("[1] means 'GO'") print("[0] means 'NO'")
C:\Users\My Name>python demo_python_ml_dtree_predict_2.py
[0]
[1] means 'GO'
[0] means 'NO'