why are neural networks not learning?

You have used wrong loss function, change this line

model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])

to, for example,

model.compile(optimizer=opt, loss='mse', metrics=['accuracy'])

Categorical cross-entropy needs a one-hot encoded y which means, you have to have a 0 or a 1 for every class. MSE is just mean squared error, so it will work. But you might try some other losses as well.

your y:

[1,0,1]

one-hot encoded y:

[[0,1], [1,0], [0,1]]

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top