Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find the MSE and MAPE metrics on test data with tensorflow

I have the following LSTM model.
How I can check the MSE or MAPE metrics on the test data?

import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import LSTM, Dense, Dropout
X_train = np.random.randn(100, 5, 1)
Y_train = np.random.randn(100, 1)
X_test = np.random.randn(20, 1)

model = Sequential()
model.add(LSTM(64, activation='relu', input_shape=(X_train.shape[1], X_train.shape[2]), return_sequences=True))
model.add(LSTM(32, activation='relu', return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(Y_train.shape[1]))
model.compile(optimizer='adam', loss='mse')
history = model.fit(X_train, Y_train, epochs=2, batch_size=100, validation_split=0.1, verbose=1)
prediction = model.predict(X_test) 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Something like this should work:

mape_loss = keras.metrics.mean_absolute_percentage_error(Y_test, prediction)
mse_loss = keras.metrics.mean_squared_error(Y_test, prediction)

Documentation

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading