import numpy as np
from keras.utils.np_utils import to_categorical
a = np.array([1,0,0,1,0])
b = to_categorical(a)
print(a)
print('--------------')
print(b)
[1 0 0 1 0]
--------------
[[0. 1.]
[1. 0.]
[1. 0.]
[0. 1.]
[1. 0.]]
格式化标签为独热编码,keras.utils.np_utils.to_categorical
最新推荐文章于 2025-04-21 14:17:18 发布
该博客介绍了如何使用Keras库中的`to_categorical`函数将离散数据转换为one-hot编码,这对于多分类问题的神经网络模型训练至关重要。通过示例展示了将一维整数数组转换为二进制类别矩阵的过程。
660

被折叠的 条评论
为什么被折叠?



