-1

The MLP I created when tested on test sets shows a test score more than 100 multiple times. Could there be any mistake in coding or the data entered?

My code:

model = Sequential()
model.add(Dense(3, input_dim = 6))
model.add(Dense(3, activation='tanh'))
model.add(Dense(1))
opt = optimizers.Adam(learning_rate=0.01)

model.compile(optimizer=opt , loss='mean_squared_error')

model.fit(x, y, epochs=ep, batch_size = 50 ,verbose=0)
test_score = model.evaluate(test_x, test_y, verbose = 0)
test_score = sqrt(test_score)
test_score = get_unscaled (test_sf, np.array([test_score]))
Kiran
  • 45
  • 5

1 Answers1

-1

model.evaluate can return two types of values:

  • Scalar: If you have not explicitly passed a value to the metric attribute to model.compile, it returns only the loss (which if it is mean squared error can be any non-negative real).
  • List of scalars: If you have passed metrics to model.compile, model.evaluate returns a list of scalars, the first element is the loss and all others are values of the metrics you passed.

To solve your question simply, pass your desired metric (say accuracy) to model.compile like model.compile(optimizer=opt, loss='mean_squared_error', metrics=['accuracy']). Running model.evaluate will then return [loss, accuracy]. Refer this.

You need to understand what you're doing before you start coding. It seems you are unclear on the meaning of mean squared error. Please do some reading up, both the theory and the Keras documentation, first.

Nikhil Kumar
  • 1,015
  • 1
  • 9
  • 14
  • Sorry! I am a beginner. Just clarifying that the error here was that the test scores were not calculated right. I used loss instead of accuracy to calculate them. Am I right? – Kiran Apr 04 '21 at 20:15
  • Yes, that is correct. There is no constraint on the loss function you've used to be upper bounded by 100. – Nikhil Kumar Apr 04 '21 at 20:18