# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/Rishit-dagli/Deep-Learning-With-TensorFlow-Blog-series/blob/master/Part%201-Getting%20started%20with%20TensorFlow%20and%20Deep%20Learning/Excercise_1_Solution.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="i0xRL3kp8p5J" colab_type="text"
# In this exercise you'll try to build a neural network that predicts the price of a house according to a simple formula.
#
# So, imagine if house pricing was as easy as a house costs 50k + 50k per bedroom, so that a 1 bedroom house costs 100k, a 2 bedroom house costs 150k etc.
#
# How would you create a neural network that learns this relationship so that it would predict a 7 bedroom house as costing close to 400k etc.
#
# Hint: Your network might work better if you scale the house price down. You don't have to give the answer 400...it might be better to create something that predicts the number 4, and then your answer is in the 'hundreds of thousands' etc.
#

# + id="1G5YoHI28k4P" colab_type="code" outputId="0f9f0d1e-6428-405f-ff32-a7e24734d29e" colab={"base_uri": "https://localhost:8080/", "height": 35}
try:
  # %tensorflow_version 2.x
except Exception:
  pass

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


# + id="3cejZj9N84jm" colab_type="code" colab={}
def house_model(y_new):
    xs=[]
    ys=[]
    for i in range(1,10):
        xs.append(i)
        ys.append((1+float(i))*50)
    
    xs=np.array(xs,dtype=float)
    ys=np.array(ys, dtype=float)

    model = keras.Sequential([keras.layers.Dense(units = 1, input_shape = [1])])
    model.compile(optimizer='sgd', loss='mean_squared_error')    
    
    model.fit(xs, ys, epochs = 4500)
    return (model.predict(y_new)[0]/100)


# + id="TQqO_Uo99Gzd" colab_type="code" outputId="946760af-2523-412e-bb55-d2953d7438e2" colab={"base_uri": "https://localhost:8080/", "height": 1000}
prediction = house_model([7.0])
print(prediction)

# + id="yKYebUkR9Hbs" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered