keras: predict_proba(), predict() and predict_classes() issues

Viewed 3786

During the predicting phase of my keras model, when I print out predicted values and classes, I'm given different probabilities in predict_proba() and predict(). Also, output for predict_classes() doesn't correspond to the probabilities. Example of code and sample of 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 of output with different predict_proba() and predict()

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 last one is also the case where the highest probability corresponds to the index = 0, but the predicted class is 1

Below another example. The highest probability is for the index = 0, but predicted class is 1

model.predict_proba -- [ 0.55918539  0.4408147 ]
model.predict -- [ 0.78916383  0.2108362 ]
predict_classes -- 1  

But the majority of cases are like below, where predict_proba() and predict() show the same values and predicted class correctly corresponds to the index with 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 it?

0 Answers
Related