-
Notifications
You must be signed in to change notification settings - Fork 3
/
model.py
45 lines (36 loc) · 924 Bytes
/
model.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
#This is iumport section
import numpy as np
print("Version of numpy is : ",np.__version__)
import tensorflow as tf
print("Version of tensorflow is : ",tf.__version__)
import matplotlib.pyplot as plt
x = np.array([1,2,3,4,5,6,7,9])
y = x*2+10
#ploting un-normalize data
plt.plot(x , y)
plt.title("1. X v/s y")
plt.show()
mean_x = x.mean()
x = x - mean_x
std_x = x.std()
x = x / std_x
mean_y = y.mean()
y = y - mean_y
std_y = y.std()
y = y / std_y
plt.plot(x , y)
plt.title("2. X v/s y")
plt.show()
print("x is : ",x)
print("y is : ",y)
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(1 , input_shape = [1,])
])
model.summary()
model.compile(optimizer = "rmsprop" , loss = "mae")
his = model.fit(x,y,epochs=10)
import matplotlib.pyplot as plt
plt.plot(his.history['loss'])
plt.title("Loss Curve")
plt.show()
print("Prediction : ",(model.predict((np.array([10,20,30,80])-mean_x)/std_x) * std_y)+mean_y)