我正在尝试使用sklearn根据我的数据集训练决策树.
当我试图将数据切片到(结果:Y,并预测变量:X)时,结果(我的标签)是真/假:
#data slicing
X = df.values[:,3:27] #X are the sets of predicting variable, dropping unique_id and student name here
Y = df.values[:,'OffTask'] #Y is our predicted value (outcome), it is in the 3rd column
这是我的方式,但我不知道这是否是正确的方法:
#convert the label "OffTask" to dummy
df1 = pd.get_dummies(df,columns=["OffTask"])
df1
我的麻烦是数据集df1将我的标签Offtask返回到OffTask_N和OffTask_Y
有人知道如何解决它吗?
最佳答案 get_dummies用于将名义字符串值转换为整数.它返回的列数与列中的唯一字符串值一样多,例如:
df={'color':['red','green','blue'],'price':[1200,3000,2500]}
my_df=pd.DataFrame(df)
pd.get_dummies(my_df)
在您的情况下,您可以删除第一个值,只要值为null,就可以认为它将是第一个值