我有一个数据集,如education{primary,graduate}
,martial status{male,female}
,job{employed, service,unemployed}
。这是分类数据集我想将其转换为浮点数,以便在numpy python中进行逻辑回归。
答案 0 :(得分:1)
一个选项是创建一个字典并将其应用于列表理解中,如:
education = {'primary':0, 'graduate':1}
ed_data = ['primary', 'primary', 'graduate', 'primary', 'graduate']
num_ed_data = [educaiton[i] for i in ed_data]
# Output: [0, 0, 1, 0, 1]