C1W1 Assignment: Housing Prices#

  • base cost 50k

  • 50k each bedroom

  • 1 bedroom 100k

  • scale 100,000 to 1

import tensorflow as tf
from tensorflow.keras import layers
import numpy as np

Generate data#

x_train = np.arange(1, 7)
y_train = 0.5 * x_train + 0.5

print([(data, label) for data, label in zip(x_train, y_train)])
[(1, 1.0), (2, 1.5), (3, 2.0), (4, 2.5), (5, 3.0), (6, 3.5)]

Create Model#

def house_model():

    model = tf.keras.Sequential([
        layers.Dense(1, input_shape=(1,))])

    model.compile(optimizer='sgd', loss='mse')

    _ = model.fit(x_train, y_train, epochs=1000)

    return model
model = house_model()
new_y = 7.0
prediction = model.predict([new_y])[0]
print(prediction)
1/1 [==============================] - 0s 101ms/step
[4.012151]