我有一个使用 Keras 进行机器学习的 Python 脚本。我正在构建 X 和 Y,它们分别是特征和标签。
标签的构建方式如下:
def main=():
depth = 10
nclass = 101
skip = True
output = "True"
videos = 'sensor'
img_rows, img_cols, frames = 8, 8, depth
channel = 1
fname_npz = 'dataset_{}_{}_{}.npz'.format(
nclass, depth, skip)
vid3d = videoto3d.Videoto3D(img_rows, img_cols, frames)
nb_classes = nclass
x, y = loaddata(videos, vid3d, nclass,
output, skip)
X = x.reshape((x.shape[0], img_rows, img_cols, frames, channel))
Y = np_utils.to_categorical(y, nb_classes) # This needs to be changed
Keras中使用的函数“to_categorical”解释如下:
分类
keras.utils.to_categorical(y, num_classes=None)
将类向量(整数)转换为二进制类矩阵。
现在我正在使用 NumPy。您可以让我知道如何构建同一行代码才能工作吗?换句话说,我正在寻找 NumPy 中“to_categorical”函数的等效项。