to_categorical(y, num_classes=None, dtype='float32')
作用:将标签转化为0nehot的形式
参数:
y:int型数组;
num_classes:标签类别个数
例子1:假如是单标签[3],一共5类
from keras.utils import to_categorical
label = [3]
l = to_categorical(label, num_classes=5)
print(l)
输出:[[0. 0. 0. 1. 0.]]
例子2:假如是多标签[2,3],一共5类
from keras.utils import to_categorical
label = [2,3]
l = to_categorical(label, num_classes=5)
print(l)
输出:[[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]]