0

Here I tried to predict the value according to the actual value using LSTM regression model. After prediction the value I need to find the prediction accuracy percentage of predict values with actual value.

I tried but it gave me large minus value.

Here is my code:

pred=model.predict(x_test)
pred = scaler_y.inverse_transform(np.array(pred).reshape ((len(pred), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test),1))).astype(int)
pred = pred[:,0]
real_test = real_test[:,0]

from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error
accuracy_regression = mean_squared_error(real_test, pred) 
print(accuracy_regression)
accuracy = 1-np.sqrt(accuracy_regression)
print("Prediction Accuracy: %.2f%%" % (accuracy*100))

Then output:

394.2002447320037
Prediction Accuracy: -1885.45%

This is wrong. Can anyone help me to solve this error?

4
  • Accuracy is a classification metric. For regression, try r2_score, mean_square_error etc. Jan 24, 2020 at 9:14
  • @ShwetaChandel Can you provide me some example, actually I tried and didn't come proper accuracy level., if you are okay . Thank you
    – team
    Jan 24, 2020 at 9:16
  • 2
    Just replace accuracy_score with r2_score. scikit-learn.org/stable/modules/generated/… Jan 24, 2020 at 9:17
  • @ShwetaChandel Got it .thank you.
    – team
    Jan 24, 2020 at 9:25

1 Answer 1

0

I suppose you are using scikit-learn ? So the Mean Squared Error (MSE) compute a risk metric corresponding to the expected value of the squared (quadratic) error or loss (more informations here)

If you want to know the accuracy score of your model you can use the function:

sklearn.metrics.accuracy_score(y_true, y_pred, normalize=True, sample_weight=None)

You can find more information about metrics in scikit-learn here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.