forked from aehilla/data310_spring2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeb3_homework_script.py
53 lines (41 loc) · 1.28 KB
/
feb3_homework_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
### Homework from class Feb 3
### home prices model
# datapoints:
# # church: 399, 4 bd, 4 ba
# # hudgins: 97, 3 bd, 1 ba
# # mathews: 347.5, 5 bd, 2 ba
# # mobjack: 289, 4 bd, 2 ba
# # moon: 250, 2 bd, 1 ba
# # newptcomfort: 229, 3 bd, 2 ba
import tensorflow as tf
import numpy as np
from tensorflow import keras
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer = 'sgd',loss='mean_squared_error')
# number of bedrooms:
xs = np.array([4.0, 3.0, 5.0, 4.0, 2.0, 3.0], dtype = float)
# price:
ys = np.array([399.0, 97.0, 347.5, 289.0, 250.0, 229.0], dtype = float)
model.fit(xs, ys, epochs= 500)
print(model.predict([4.0]))
# output is approx. 299
print(model.predict([3.0]))
# output is approx. 235
print(model.predict([2.0]))
# output is approx. 169
print(model.predict([5.0]))
# output is approx. 365
### re-run model using number of bathrooms:
# number of bathrooms:
xs = np.array([4.0, 1.0, 2.0, 2.0, 1.0, 2.0], dtype = float)
# price:
ys = np.array([399.0, 97.0, 347.5, 289.0, 250.0, 229.0], dtype = float)
model.fit(xs, ys, epochs= 500)
print(model.predict([4.0]))
# output is approx. 426
print(model.predict([3.0]))
# output is approx. 346
print(model.predict([2.0]))
# output is approx. 266
print(model.predict([1.0]))
# output is approx. 186