Hi all
My house price prediction is completely off.
Here is my code:
# GRADED FUNCTION: house_model
def house_model(y_new):
xs = np.arange(21)
ys = np.arange(0.05+0*0.05, 0.05+21*0.05, 0.05)
print(xs,ys)
model = keras.Sequential(
[
layers.Dense(1, input_shape=[1]),
]
)
model.compile(optimizer=keras.optimizers.SGD(learning_rate=1e-5), loss="mean_squared_error", metrics=["mae"])
model.fit(xs, ys, epochs=500)
return model.predict(y_new)[0]
What’s wrong?
Thanks for your time
Jaime
Hi @Jaime_Gonzalez ,
try to take a better look at the length of your xs, then I dunno if you actually need to set a learning rate.
Best
Thanks @maurizioscibilia , I did that
my code now looks like:
# GRADED FUNCTION: house_model
def house_model(y_new):
xs = np.arange(1,21,1)
ys = np.arange(0.5+1*0.5, 0.5+21*0.5, 0.5)
print(xs,ys)
model = tf.keras.Sequential(
[
layers.Dense(1, input_shape=[1]),
]
)
model.compile(optimizer=keras.optimizers.SGD(learning_rate=6e-3), loss="mean_squared_error", metrics=["mae"])
model.fit(xs, ys, epochs=500)
return model.predict(y_new)[0]
Notice how only a learning step of 6e-3 gets me close to an accurate prediction. Other learning step sizes return infinity or nan or very inaccurate values. Why is this? And how come others did not have this problem?
Sorry, I had just now the time to read fully your reply.To answer your question, most of the times you should not set any learning rate and leave its default value. I guess it was that.
Best
It can’t be that because my code only works when I ALTER the learning rate
please note that posting your code is against coursera honor code. Please post the output of your code from now.
Coming to your code , it is totally wrong . Solution for your code is to take xs,ys values to be apt i.e., xs takes the no .of bedrooms for a house and ys takes the cost of respective house . Each shall contain six values and try not to overthink about code at model.compile , it must have only optimizer and loss .
Finally, dont change the starter code .
Hope you got the answer.
please leave a reply about your solution
1 Like
notice also that the default step size of numpy arange is 1, so just adding it explicitly didn’t actually change anything…
step integer or real, optional
Spacing between values. For any output out , this is the distance between two adjacent values, out[i+1] - out[i]
. The default step size is 1. If step is specified as a position argument, start must also be given.
https://numpy.org/doc/stable/reference/generated/numpy.arange.html
1 Like