Reputation: 321
I want to train a Neural Network to predict classes/ numbers out of an input which is also a number; so the mapping is number->number (input->output).
But when considering the datatype and the values I am not sure whether to treat the problem as a classification or regression problem.
As an example the first rows of the data look like this:
Since my target ranges from 0-14 my first approach was to treat this problem as a classification problem where i choose the size of the output layer to be size = 15.
Here is my NN model:
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Flatten, Activation, Dropout, LSTM, Conv1D
model.add(Flatten())
model.add(Dense(8, activation='relu'))
model.add(Dense(15, activation='softmax'))
model.add(Activation('softmax'))
model.compile(loss='sparse_categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
model.summary()
history = model.fit(X_train, y_train, epochs=100, batch_size=128)
which predicts always the same classification values:
The accuracy converges after a few epochs and does not change any more at about 20%.
Why is the model always predicting the same class? what am I missing here? Should I treat this problem as a regression task?
Upvotes: 0
Views: 537
Reputation: 20302
Typically, numbers (or any numerics) are used for regression and labels (any non-numerics) are used for classification.
Regression Data:
Classification Data:
Look at the data types in both the regression example and the classification example.
Upvotes: 1
Reputation: 368
Since you have already applied 'softmax' in model.add(Dense(15, activation='softmax'))
so there is no need to apply it again by model.add(Activation('softmax'))
.
Remove it and try.
Upvotes: 1