【发布时间】:2018-10-30 16:05:45
【问题描述】:
我已经使用 keras 层构建并训练了一个顺序二元分类模型。一切似乎都很好。直到我开始使用 predict 方法。这个函数开始给我一个奇怪的指数值而不是概率。 This what I get after training and using predict method on the model
这个分类模型有两个类别,比如说猫或狗,所以我期待结果类似于 [99.9999, 0.0001],表明它是一只猫。我不确定如何解释我返回的值。
这是我的代码:
# Get the data.
(train_texts, train_labels), (val_texts, val_labels) = data
train_labels = np.asarray(train_labels).astype('float32')
val_labels = np.asarray(val_labels).astype('float32')
# Vectorizing data
train_texts,val_texts, word_index = vectorize_data.sequence_vectorize(
train_texts, val_texts)
# Building the model architecture( adding layers to the model)
model = build_model.simple_model_layers(train_texts.shape[1:])
# Setting and compiling with the features like the optimizer, loss and metrics functions
model = build_model.simple_model_compile(model=model)
# This is when the learning happens
history = model.fit(train_texts,
train_labels,
epochs=EPOCHS,
validation_data=(val_texts, val_labels),
verbose=VERBOSE_OFF, batch_size=BATCH_SIZE)
print('Validation accuracy: {acc}, loss: {loss}'.format(
acc=history['val_acc'][-1], loss=history['val_loss'][-1]))
# loading data to predict on
test_text = any
with open('text_req.pickle', 'rb') as pickle_file:
test_text = pickle.load(pickle_file)
print('Lets make a prediction of this requirement:')
prediction = model.predict(test_text, batch_size=None, verbose=0, steps=None)
print(prediction)
【问题讨论】:
-
神经网络认为这个奇怪的值是 0。它不是指数,而是 2.977094 * 10^{-12}
-
欢迎来到 StackOverflow。请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您描述的问题。
-
那个输出只是一个科学计数法的数字。
-
实际上得到这个数字并不是什么大问题。我的问题是我真的不知道该怎么做。我在帖子中添加了更多信息:“这个分类模型有两个类别,比如说猫或狗,所以我期待结果类似于 [99.9999, 0.0001] 表明它是一只猫。我不确定如何解释我返回的值。”
-
如果使用sigmoid作为最后一层,只有一个值是正常的。它对应于类为1的概率
标签: python tensorflow keras