如何使用 tensorflow 在测试数据上找到 MSE 和 MAPE 指标
How to find the MSE and MAPE metrics on test data with tensorflow
我有以下 LSTM 模型。
如何检查测试数据的 MSE 或 MAPE 指标?
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)
像这样的东西应该可以工作:
mape_loss = keras.metrics.mean_absolute_percentage_error(Y_test, prediction)
mse_loss = keras.metrics.mean_squared_error(Y_test, prediction)
我有以下 LSTM 模型。 如何检查测试数据的 MSE 或 MAPE 指标?
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)
像这样的东西应该可以工作:
mape_loss = keras.metrics.mean_absolute_percentage_error(Y_test, prediction)
mse_loss = keras.metrics.mean_squared_error(Y_test, prediction)