I am new in Keras and would want to apply a neural network on this dataset: https://www.drivendata.org/competitions/57/nepal-earthquake/

I have proprocessed the dataset transforming categorical variables into numerical with pd.get_dummies pandas method. Also, target (that is 1, 2 or 3 - depending on the damage grade) is tranformed into three columns indicating the probability of being one of those values.

The NN I wrote is simple, but I don't understand what are the values that predict method returns.

# first neural network with keras tutorial
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
import tensorflow as tf
import keras.backend as K

# define the keras model
model = Sequential()
# 12 8 3 Accuracy: 57.08
# 25 12 3 Accuracy: 56.89
model.add(Dense(25, input_dim=68, activation='relu'))
model.add(Dense(12, activation='relu'))
model.add(Dense(3, activation='softmax'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[get_f1])
# fit the keras model on the dataset
model.fit(X, y, epochs=5, batch_size=10)

predicted = model.predict(test)

This is the output for the first individual:

array([0.09522187, 0.57914054, 0.32563758], dtype=float32)

Any idea?

PD: If you request some additional information or code, please let me know :)

Thanks a lot!!!


The output of softmax is a probability distribution, It gives the probability of each class of being correct. So, you have to find out the array index of the max value in array.

predicted_class = np.argmax(predicted)
  • $\begingroup$ Thanks! That helps! $\endgroup$
    – Thabby07
    Mar 14 '20 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.