普通数据改为onehot编码,onehot转换为普通数据

普通数据改为onehot编码,onehot转换为普通数据_第1张图片
在这里插入图片描述

一维数组转one-hot编码

方法一:

from sklearn.preprocessing import OneHotEncoder
enc=OneHotEncoder()
enc.fit(train_label)

方法二:

import numpy as np
from keras.utils import to_categorical
Y_pred_classes=to_categorical(Y_pred_classes)

onehot编码转一维数组

Y_pred_classes = np.argmax(Y_prediction,axis = 1)

你可能感兴趣的:(机器学习,python,深度学习,numpy)