0

I am attempting to train a neural network to do simple mapping i.e. X to Y. In this case I am attempting to map a value to its respective error. Both X and Y are arrays of size 1077.

The data has a lot of noise and the relationship is, essentially, non-existent. Therefore, I decided to go with classification rather than regression. If I use MSE (seen below), the accuracy never goes above zero and the loss is enormous and non-changing.

# Data preprocessing
from sklearn.model_selection import train_test_split

A_train, A_test, Aerror_train, Aerror_test = train_test_split(A, A_error, 
test_size=0.33, random_state=42)

# Defining and compiling the model
model = Sequential() # initializing a sequential model
model.add(Dense(1, activation = 'relu', input_shape = (1,))) #first layer 
model.add(Dropout(0.2)) 
model.add(Dense(1, activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation ='softmax'))

model.summary()
model.compile(loss = 'mean_squared_error', optimizer = 'sgd', 
metrics = ['accuracy'] ) #sgd = stochastic gradient descent, cat_ce = 
probability that increases as the predicted and actual values diverge

If I try to use the loss function sparse categorical crossentropy, since I want to do multilabel classification

I receive the following error:

InvalidArgumentError (see above for traceback): Received a label value of 
15614 which is outside the valid range of [0, 1).
ashune
  • 11
  • 1
    What is the actual task? You can't just choose classification over regression on a whim, it depends on the task. If you want to do classification, you have a minimum of two classes, and your model is configured for a single class, that's why the loss does not change. – Dr. Snoopy Jul 08 '19 at 08:35
  • A training set of ~1k is not very big. It’s hard to suggest directions without knowing the nature of the data or the task. How does your error metric work with conventional classifieds like nominal logistic? When you scatterplot x vs y is there a relationship to be had? If you order y by x and make a 4-plot, what does each pane tell you? – EngrStudent Jul 08 '19 at 10:24
  • The independent variable in this case is a physical value (the semi-major axis of a satellite) while the dependent variable is the associated error that comes from comparing the predicted semi-major axis with the actual known semi-major axis. So there should be 1077 classes (an error for each data point) and I'll change my model to reflect that. The scatterplot indicates no relationship at all but I will make a 4 plot and get back to you. – ashune Jul 08 '19 at 13:13
  • Since your are using MSE as your loss, you are in fact doing *regression*, for which both your output softmax single-node layer and accuracy as a metric are **meaningless**; see [What function defines accuracy in Keras when the loss is mean squared error (MSE)?](https://stackoverflow.com/questions/48775305/what-function-defines-accuracy-in-keras-when-the-loss-is-mean-squared-error-mse/48788577#48788577) – desertnaut Jul 08 '19 at 16:39
  • But if I try to use sparse categorical cross entropy I receive the above error. Is it because the number of nodes in the output layer should be the number of classes? – ashune Jul 08 '19 at 16:44

0 Answers0