How to compute Receiving Operating Characteristic (ROC) and AUC in keras?

Due to that you can’t calculate ROC&AUC by mini-batches, you can only calculate it on the end of one epoch. There is a solution from jamartinh, I patch the code below for convenience: from sklearn.metrics import roc_auc_score from keras.callbacks import Callback class RocCallback(Callback): def __init__(self,training_data,validation_data): self.x = training_data[0] self.y = training_data[1] self.x_val = validation_data[0] self.y_val … Read more

How do I install Keras and Theano in Anaconda Python on Windows?

It is my solution for the same problem Install TDM GCC x64. Install Anaconda x64. Open the Anaconda prompt Run conda update conda Run conda update –all Run conda install mingw libpython Install the latest version of Theano, pip install git+git://github.com/Theano/Theano.git Run pip install git+git://github.com/fchollet/keras.git

Keras model.summary() result – Understanding the # of Parameters

The number of parameters is 7850 because with every hidden unit you have 784 input weights and one weight of connection with bias. This means that every hidden unit gives you 785 parameters. You have 10 units so it sums up to 7850. The role of this additional bias term is really important. It significantly … Read more

How to get reproducible results in keras

You can find the answer at the Keras docs: https://keras.io/getting-started/faq/#how-can-i-obtain-reproducible-results-using-keras-during-development. In short, to be absolutely sure that you will get reproducible results with your python script on one computer’s/laptop’s CPU then you will have to do the following: Set the PYTHONHASHSEED environment variable at a fixed value Set the python built-in pseudo-random generator at a … Read more

Keras, how do I predict after I trained a model?

model.predict() expects the first parameter to be a numpy array. You supply a list, which does not have the shape attribute a numpy array has. Otherwise your code looks fine, except that you are doing nothing with the prediction. Make sure you store it in a variable, for example like this: prediction = model.predict(np.array(tk.texts_to_sequences(text))) print(prediction)

NaN loss when training regression network

Regression with neural networks is hard to get working because the output is unbounded, so you are especially prone to the exploding gradients problem (the likely cause of the nans). Historically, one key solution to exploding gradients was to reduce the learning rate, but with the advent of per-parameter adaptive learning rate algorithms like Adam, … Read more