【问题标题】:Handle categorical class labels for scikit-learn MLPClassifier处理 scikit-learn MLPClassifier 的分类类标签
【发布时间】:2018-11-13 07:24:42
【问题描述】:

我有一个用于分类目的的手写数据集,其中的类来自a-z。如果我想使用MLPClassifier,我想我不能直接使用这样的分类类,因为 scikit-learn 中的 MLP 实现只处理数字类。因此,这里应该采取什么适当的行动?将这些类转换为从 1 到 28 编号怎么样,有意义吗?如果没有,scikit-learn 是否为类标签提供特殊的编码机制来处理这种情况(我想 one-hot 编码不是这里的选项)?

谢谢

【问题讨论】:

  • Scikit learn 可以自己处理分类类标签。无需做任何事情。你试过吗?你试过什么?

标签: machine-learning scikit-learn neural-network multilabel-classification


【解决方案1】:

您可能需要预处理数据,因为scikit-reather只致电数值。在这种情况下,我想预测交易的货币。货币在ISO代码中表示,因此LabelEncoder用于将其转换为数字类别(即:1,2,3 ......):

#Import the object LabelEncoder
from sklearn.preprocessing import LabelEncoder

#defining class column
my_encoder = LabelEncoder()
my_class_currency = np.array(my_encoder.fit_transform(my_data['currency'])).reshape(-1,1)
#Create a "diccionary" to translate the categories into the actual values once you have the output
my_class_decoder = list(np.unique(my_data['currency']))

【讨论】:

    猜你喜欢
    • 2016-10-17
    • 2017-08-05
    • 2014-02-17
    • 2015-07-30
    • 2012-10-29
    • 2014-11-19
    • 2013-04-30
    • 2020-01-28
    • 2016-01-24
    相关资源
    最近更新 更多