W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
demo_python_ml_dtree_predict_1.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, 7, 1]])) print("[1] means 'GO'") print("[0] means 'NO'")
[email protected]
:/home/python#python demo_python_ml_dtree_predict_1.py
[1]
[1] means 'GO'
[0] means 'NO'