【发布时间】:2021-12-16 21:24:09
【问题描述】:
我有一个非常简单的神经网络,它可以在 250 个时期工作,在最后一个时期它显示 mae = 0.1397,但是,如果我尝试获得 model.evaluate((m * test_x + b), predict_y)),那么 mae 大约是 44009.296875。
为什么差别这么大?
这是我的代码:
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))
【问题讨论】:
标签: python tensorflow machine-learning keras deep-learning