我正在做一个作业,我们正在使用scikit中的OneHotEncoder来学习将所有类别打印出来。以下是数据示例和我用于转换它的代码:
grade sub_grade short_emp emp_length_num home_ownership term
0 B B2 0 11 RENT 36 months
1 C C4 1 1 RENT 60 months
2 C C5 0 11 RENT 36 months
3 C C1 0 11 RENT 36 months
4 A A4 0 4 RENT 36 months
5 E E1 0 10 RENT 36 months
代码:
^{pr2}$我收到的错误出现在术语列上:
ValueError: could not convert string to float: ' 36 months'
scikit learn的
OneHotEncoder
支持0.20.0中的字符串。在OneHotEncoder
不支持字符串功能。您必须先将它们转换为整数,例如使用LabelEncoder
。另一个选择是对所有列使用LabelBinarizer
。在见How to do Onehotencoding in Sklearn Pipeline。在
相关问题 更多 >
编程相关推荐