I'm working in Keras/TensorFlow. This is my Keras model:
model = Sequential() model.add(Dense(512, input_shape=(max_words,))) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(num_classes)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
After training step and test step, I'm coding a method that take the input (which i don't know his class) e this method returns the class prediction with level of confidence. Now this method returns only the prediction of class. This is the method:
def predict(input): try: x_prediction = tokenize.texts_to_matrix(input) q = model.predict(np.array([x_prediction,])) predicted_label = text_labels[np.argmax(q)] print("Prediction: " + predicted_label + "\n") except: return "Error"
What should I add in the method to get the confidence level of the respective prediction? I don't want use the confidence of variable 'q' but I want to use the Bayes Approach. How can I do? Thanks