code_6.py 384 字节
Newer Older
ToTensor's avatar
ToTensor 已提交
1 2 3 4 5 6 7
from sklearn.preprocessing import Label Encoder # 导入标签编码工具
from keras.utils.np_utils import to_categorical # 导入One-hot编码工具
label_encoder = Label Encoder()
y = label_encoder.fit_transform(y_label) # 标签编码
y = to_categorical(y, 10) # 将标签转换为One-hot编码
X = np.array(X) # 将X从列表转换为张量数组
X = X/255 # 将X张量归一化