I have a very simple neural-network which works in 250 epochs and in the last epoch it shows the mae = 0.1397
, however, if i try to get the model.evaluate((m * test_x + b), predict_y))
then the mae is about 44009.296875
.
Why there is such big difference ?
Here is my code:
import tensorflow as tf
from tensorflow.keras import Input
from tensorflow.keras.layers import Dense
from tensorflow.keras.utils import plot_model
import numpy as np
import matplotlib.pyplot as plt
train_x = np.arange(2000)
m = 5
b = 4
train_y = m * train_x + b
# -----------------------------------------------------
# Create a Sequential Nerual Network
model = tf.keras.Sequential()
model.add(Input(shape=(1,), name="input_layer"))
model.add(Dense(10, activation="relu"))
model.add(Dense(1, activation=None, name="output_layer"))
# -----------------------------------------------------
# Compile the model
model.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),
metrics=["mae"])
# -----------------------------------------------------
# Train the model
model.fit(train_x, train_y, epochs=250)
# -----------------------------------------------------
# Test the model
test_x = np.arange(2000, 2400)
predict_y = model.predict([test_x])
# ------------------------------------------------------
# Evaluation
print("Evaluate Testing : ", model.evaluate((m * test_x + b), predict_y))