我有一个Python脚本,它使用Keras进行机器学习。我正在构建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_category”解释如下:
to_categorical
keras.utils.to_categorical(y, num_classes=None)
Converts a class vector (integers) to binary class matrix.
现在我用的是NumPy。你能告诉我如何建立相同的代码行,以便工作?换言之,我正在寻找与NumPy中的“to-tu-category”功能相当的功能。在
像这样的东西(我不认为有内置的):
这里有一个简单的方法:
尝试使用get_dummies。在
相关问题 更多 >
编程相关推荐