I'm new in using tensorflow. I'm simply trying to get the relationship between x and y values. Their relationship is described by the equation: y = 50 + 50*x. See code below.
import tensorflow as tf
import numpy as np
from tensorflow import keras
# GRADED FUNCTION: house_model
def house_model(y_new):
xs = np.array([0, 1,2,3,4,5], dtype = float)
ys = np.array([50000, 100000,150000,200000,250000,300000], dtype = float)
#ys = ys/100000
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(128))
model.add(tf.keras.layers.Dense(128))
model.compile(optimizer = "sgd", loss = "mean_squared_error", metrics = ["accuracy"])
model.fit(xs, ys, epochs = 500)
return model.predict([y_new])
prediction = house_model([7.0])
print(prediction)
My question is why does the loss became NaN and accuracy became 0.0000e+00 if I don't rescale ys? (I commented out the rescaling in the code above). Based from what I found in the internet, you should normalized the input to have accurate results but in this case it is the output I'm normalizing to get good results. Can someone please explain to be why is this happening?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…