Run ❯
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
Python code
data.csv
import pandas from sklearn import tree from sklearn.tree import DecisionTreeClassifier df = pandas.read_csv("data.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'")
Age,Experience,Rank,Nationality,Go 36,10,9,UK,NO 42,12,4,USA,NO 23,4,6,N,NO 52,4,4,USA,NO 43,21,8,USA,YES 44,14,5,UK,NO 66,3,7,N,YES 35,14,9,UK,YES 52,13,7,N,YES 35,5,9,N,YES 24,3,5,USA,NO 18,3,7,UK,YES 45,9,9,UK,YES
[1]
[1] means 'GO'
[0] means 'NO'