我有一个分类numpy数组,想把它转换成整数?

时间:2017-10-06 11:38:04

标签: python numpy machine-learning

我有一个数据集,如education{primary,graduate}martial status{male,female}job{employed, service,unemployed}。这是分类数据集我想将其转换为浮点数,以便在numpy python中进行逻辑回归。

1 个答案:

答案 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]