【发布时间】:2019-10-02 01:56:35
【问题描述】:
我在 pandas 数据框上为某些列安装了 Onehotencoder:
{ 'country', 'female', 'at_weekend' }
现在,我想在单个字典上使用这个 Onehotencoder
{ 'country': 'US', 'female': True, 'at_weekend': True }
限制是我不能使用 pandas 来转换这本字典。 不过,我当然可以使用 Numpy,而 Scikit 也可以学习。
这是我尝试过的,但不起作用:
object_dict = { 'country': 'US', 'female': True, 'at_weekend': True }
a = np.array(object_dict)
b = one_hot_encoder.transform(a.reshape(1,-1))
我收到此错误
TypeError: unhashable type: 'dict'
【问题讨论】:
标签: python-3.x scikit-learn one-hot-encoding