Issues using Keras np_utils.to_categorical

I’m trying to make an array of one-hot vector of integers into an array of one-hot vector that keras will be able to use to fit my model. Here’s the relevant part of the code: Below is an image showing what Y_train and dummy_y actually are. I couldn’t find any documentation for to_categorical that could help me. Thanks in advance.

LSTM Keras input shape confusion

I am trying to build a predictive model on stock prices. From what I’ve read, LSTM is a good layer to use. I can’t fully understand what my input_shape needs to be for my model though. Here is the tail of my DataFrame I then split the data into train / test This yields: Here’s where I am getting confused. … Read more

Where do I call the BatchNormalization function in Keras?

Just to answer this question in a little more detail, and as Pavel said, Batch Normalization is just another layer, so you can use it as such to create your desired network architecture. The general use case is to use BN between the linear and non-linear layers in your network, because it normalizes the input … Read more

What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?

Simply: categorical_crossentropy (cce) produces a one-hot array containing the probable match for each category, sparse_categorical_crossentropy (scce) produces a category index of the most likely matching category. Consider a classification problem with 5 categories (or classes). In the case of cce, the one-hot target may be [0, 1, 0, 0, 0] and the model may predict [.2, .5, .1, .1, .1] (probably right) In the … Read more

Can I run Keras model on gpu?

Yes you can run keras models on GPU. Few things you will have to check first. your system has GPU (Nvidia. As AMD doesn’t work yet) You have installed the GPU version of tensorflow You have installed CUDA installation instructions Verify that tensorflow is running with GPU check if GPU is working sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) for TF … Read more

What is the use of train_on_batch() in keras?

For this question, it’s a simple answer from the primary author: With fit_generator, you can use a generator for the validation data as well. In general, I would recommend using fit_generator, but using train_on_batch works fine too. These methods only exist for the sake of convenience in different use cases, there is no “correct” method. train_on_batch allows you to expressly update … Read more