Keras: predict_proba (), predict () and predict_classes ()
During the prediction phase of my keras model, when I print the predicted values ββand classes, I am given different probabilities in pred_proba () and pred (). Also, the output for class_prediction () does not match the probabilities. Sample code and sample printout below:
Code:
p = pd.read_csv("test.csv", header=None)
p = np.reshape(p.values, (50, seq_length))
for i in range(len(p)):
p[i] = scaler.fit_transform(p[i])
p = np.reshape(p, (50, seq_length, 1))
model.predict(p, batch_size=50)
model.predict_classes(p, batch_size=50)
model.predict_on_batch(p)
model.predict_proba(p, batch_size=50)
for i in zip(model.predict_proba(p, batch_size=50), model.predict_classes(p, batch_size=50), model.predict(p, batch_size=50)):
print("model.predict_proba", "--", i[0], "model.predict","--", i[2], "predict_clases", "--", i[1])
Sample output with different predict_proba()
andpredict()
model.predict_proba -- [ 0.18768159 0.81231844] model.predict -- [ 0.18982948 0.81017047] predict_classes -- 1
model.predict_proba -- [ 0.55918539 0.4408147 ] model.predict -- [ 0.78916383 0.2108362 ] predict_classes -- 1
The latter is also the case where the highest probability is index = 0, but the predicted class is 1
Below is another example. Highest probability for index = 0, but predicted class is 1
model.predict_proba -- [ 0.55918539 0.4408147 ] model.predict -- [ 0.78916383 0.2108362 ] predict_classes -- 1
But most of the cases as shown below, where pred_proba () and pred () show the same values, and the predicted class matches the index correctly with the highest probability
model.predict_proba -- [ 0.39802018 0.60197979] model.predict -- [ 0.39802018 0.60197979] predict_classes -- 1
Maybe I don't understand how to read this? Thanks to
source to share
No one has answered this question yet
Check out similar questions: