How To Use Keras Predict_proba To Output 2 Columns Of Probability?
I use this code to predict the probability of 0 and 1 in x_test, but the result is only one column of probability. I really don’t know whether the probability of this column is t
Solution 1:
First, you need to convert y_train
to one-hot encoding by
from sklearn.preprocessingimportLabelEncoderfrom keras.utilsimport np_utils
encoder = LabelEncoder()
encoder.fit(y_train)
encoded_y = encoder.transform(y_train)
y_train = np_utils.to_categorical(encoded_y)
running this code, y_train
will become
array([[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.]], dtype=float32)
Secondly, you need to change the output layer to
model.add(Dense(2, activation='softmax'))
with these two modifications, you will get the desired output.
Post a Comment for "How To Use Keras Predict_proba To Output 2 Columns Of Probability?"