jeffs
jeffs

Reputation: 321

Classification or regression for prediction

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

Answers (2)

ASH
ASH

Reputation: 20302

Typically, numbers (or any numerics) are used for regression and labels (any non-numerics) are used for classification.

https://medium.com/quick-code/regression-versus-classification-machine-learning-whats-the-difference-345c56dd15f7

Regression Data:

enter image description here

Classification Data:

enter image description here

Look at the data types in both the regression example and the classification example.

Upvotes: 1

Ratnesh Kushwaha
Ratnesh Kushwaha

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

Related Questions