【发布时间】:2020-03-01 21:59:49
【问题描述】:
查看OneHotEncoder 的文档,似乎没有办法将特征名称包含为 OneHot 向量的前缀。有谁知道解决这个问题的方法?我错过了什么吗?
示例数据框:
df = pd.DataFrame({'a':['c1', 'c1', 'c2', 'c1', 'c3'], 'b':['c1', 'c4', 'c1', 'c1', 'c1']})
from sklearn.preprocessing import OneHotEncoder
onehot = OneHotEncoder()
onehot.fit(df)
onehot.get_feature_names()
array(['x0_c1', 'x0_c2', 'x0_c3', 'x1_c1', 'x1_c4'], dtype=object)
如果给编码器提供了一个数据帧,我希望有可能获得类似的东西:
array(['a_c1', 'a_c2', 'a_c3', 'b_c1', 'b_c4'], dtype=object)
【问题讨论】:
标签: python pandas machine-learning scikit-learn