运行 ❯
获取您的
自己的 Python
服务器
×
更改方向
更改主题,暗色/亮色
前往 Spaces
Python 代码
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, 6, 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
[0]
[1] 表示 'GO'
[0] 表示 'NO'