预测函数返回指数值

时间:2018-10-30 16:05:45

标签: python tensorflow keras

我已经使用keras层构建并训练了顺序二进制分类模型。一切似乎都正常。直到我开始使用预测方法。这个函数开始给我一个怪异的指数值,而不是概率。 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)

1 个答案:

答案 0 :(得分:-1)

通常,未倾斜的数据在训练时会转换为其日志值。 所以

np.exp(your_value)

可能是您要找的东西。