【发布时间】:2020-08-31 17:52:01
【问题描述】:
我正在尝试在 python 中运行逻辑回归。我的数据由数字和分类数据组成。我想使用性别、年龄和食物偏好来预测某人是否喜欢猫。
我在想我需要对 Food_preference 进行一次热编码(见下文),但不确定具体该怎么做。能否请你帮忙?谢谢!
原始数据框
Name Gender Age Like_cats Food_preference
John M 30 Yes Apple
John M 30 Yes Orange
John M 30 Yes Steak
Amy F 20 No Apple
Amy F 20 No Grape
所需的数据帧
Name Gender Age Like_cats Apple Orange Steak Grape
John M 30 Yes 1 1 1 0
Amy F 20 No 1 0 0 1
【问题讨论】:
标签: python logistic-regression one-hot-encoding