我有一个用于分类目的的手写数据集,其中的类来自a-z
. 如果我想使用MLPClassifier,我想我不能直接使用这样的分类类,因为 scikit-learn 中的 MLP 实现只处理数字类。因此,这里应该采取什么适当的行动?将这些类转换为从 1 到 28 的编号如何,是否有意义?如果没有,scikit-learn 是否为类标签提供了特殊的编码机制来处理这种情况(我猜这里不是单热编码的选项)?
谢谢
您可能需要预处理数据,因为 scikit-learn 只处理数值。在这种情况下,我想预测交易的货币。货币以 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']))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句