【发布时间】:2019-05-29 13:04:18
【问题描述】:
如果我有一组目标,也就是 [1,0,9,9,7,5,4,0,4,1] 并且我使用 model.predict(X),Keras 会为 10 个样本中的每一个返回一个 6 项数组。它返回 6 个项目,因为有 6 个可能的目标(0、1、4、5、7、9),并且 keras 返回一个小数/浮点数(对于每个标签),表示其中任何一个是正确目标的可能性。例如,对于第一个示例 - 其中 y=1 Keras 返回一个如下所示的数组:[.1, .4,.003,.001,.5,.003]。
我想知道哪个值与哪个目标匹配(0.1 是指 1 是因为它是数据集中的第一个,还是 0 是因为它是最小的数字,或者 9 是因为它是最后一个数字,等等)。 Keras 如何对其预测进行排序? The documentation 似乎没有明确说明这一点;它只说
“为输入样本生成输出预测。”
所以我不确定如何将标签与预测结果相匹配。
编辑:
这是我的模型和训练代码:
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.25, random_state=42)
Y_train = to_categorical(y_train)
Y_test = to_categorical(y_test)
sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
x = Conv1D(64, 5, activation='relu')(embedded_sequences)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x)
x = Conv1D(64, 5, activation='relu')(x)
x = MaxPooling1D(4)(x) # global max pooling
x = Flatten()(x)
x = Dense(64, activation='relu')(x)
preds = Dense(labels_Index, activation='softmax')(x)
model = Model(sequence_input, preds)
model.fit(X_train, Y_train, epochs=10, verbose = 1)
【问题讨论】:
标签: python keras label predict