demo_ml_dtree_predict2.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_ml_dtree_predict2.py
[0]
[1] means 'GO'
[0] means 'NO'