1

How is the accuracy calculated when the problem is a regression one?

I'm working on a regression problem to predict how much electricity each user USES each day,I use keras build a LSTM model to do this time series prediction. At the beginning, I use the 'accuracy' as the metrics, and when run

model.fit(...,verbose=2,...)

val_acc has a value after every epoch. And in my result, the value doesn't change, it's always the same value.

Then I realized that the regression problem was that there was no concept of accuracy, and then I started to wonder, how is that accuracy calculated?

I have a guess that when metrics is 'accuracy' in the regression question, accuracy is also calculated in a similar way to the classification problem: the number of predicted values equal to true values divided by the total sample size.

Am I right?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
JALS
  • 23
  • 5

2 Answers2

0

In regression you use metrics that measure how far your prediction is from the actual value, such as Squared Error, Mean Squared Error, etc. Please see How to determine the accuracy of regression? Which measure should be used?

When building a keras LSTM model, you usually build a "skeleton" first, then you compile, fit and at the end, predict. During the compile step you need to define your loss function (see Keras documentation on Sequential models) and a metric, so you could do e.g.

model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['mean_squared_error'])

(see Keras documentation on metrics). Therefore, if you put accuracy as a metric in a regression setting, you would not get reasonable results, as this metric is designed only for categorical tasks.

Tomasz Bartkowiak
  • 12,154
  • 4
  • 57
  • 62
  • Thank you~I'm sorry for asking a question which already has an answer, because I didn't find it when I search for the answer to my question.Now I know my guess is right,thank you again~ – JALS Sep 01 '19 at 15:00
0

Yes, the accuracy is computed in exactly the same way as in classification, keras does not do any kind of adjustment. As you say it makes no sense to use the accuracy (which is a classification metric) for a regression problem.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140
  • Thank you for your answer.In this way, I can finally get rid of this problem~happy! – JALS Sep 01 '19 at 14:49