【发布时间】:2019-01-26 18:21:26
【问题描述】:
我是 python 和机器学习的新手,因为我每天都在学习。我想澄清一些事情,这次是关于我的标签。我有 2004 个课程可供分类。我正在从文件名手动构建标签。如下所示
import numpy as np
path = "D:/data/image/1/1/asas1231231231.jpg"
label = np.zeros(2004)
# The line to read the 4th index from path and converting it into integer and then pass it on to the array to have the label
label[int(path.rsplit('/')[4]) - 1 ] = 1
# Which gives me
print(label[0])
1.0
现在我的文件名直到 2004 年,并且在每次读取图像的迭代中,我也在标签中制作标签,然后将它们附加到列表中,例如
training_labels = []
training_labels.append(label)
但是在对标签进行了一些研究之后,我开始了解 np_utils.to_categorical
np_utils.to_categorical(1,2004)
给我
array([[1., 0., 0., ..., 0., 0., 0.]])
我的问题是两者之间有什么区别? 谁能给我解释一下。 我还打印了我的形状
(2004 年,)
有了 np_utils 我得到了
(1,2004)
【问题讨论】: