【问题标题】:Label Encoding of multiple columns without using pandas不使用熊猫的多列标签编码
【发布时间】:2017-06-05 09:49:31
【问题描述】:

有没有一种简单的方法来标记编码而不使用 pandas 的多列?

就像只使用 numpy 和 sklearn 的 preprocessing.LabelEncoder()

【问题讨论】:

  • AFAIK 您需要遍历列并使用 LabelEncoder 转换每个 string

标签: python python-3.x numpy machine-learning scikit-learn


【解决方案1】:

一种解决方案是遍历列,将它们转换为数值,使用LabelEncoder

le = LabelEncoder()

cols_2_encode = [1,3,5] 

for col in cols_2_encode:
    X[:, col] = le.fit_tramsform(X[:, col])

【讨论】:

    猜你喜欢
    • 2018-05-30
    • 2022-11-25
    • 2020-02-01
    • 2015-05-28
    • 2021-04-29
    • 2021-07-28
    • 2016-09-15
    • 1970-01-01
    相关资源
    最近更新 更多