Tensorflow course notes
Traditional programming
Rules ---> | Traditional |
Data ---> | programming | --> answers
ML
Answers---> | Machine |
Data ---> | Learning | --> Rules
The "Hello world" of neural networks
Defining a neural network with Keras. A neural network is a set of function which can learn patterns.
model = tf.keras.Sequential([keras.layers.Dense((units = 1, input_shape =[1])])
This nn has only one layer and one unit.
There are two math functions that help us with nn.
model.compile(optimizer='sgd' , loss='mean_squared_error')
The neural network doesn´t know what is X and Y, it will guess results. The loss function measures how good or bad was the result of the neural network and the optimizer will use that value to obtain the next guess.
I will use this data set with NumPy library
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
#it will train the model 500 times
model.fit(xs, ys, epoch(500))
# it will predict the result for the x value 10.0
print(model.predict([10.0]))
This will print a result close to 19.0 but not exactly 19 because neural networks work based on probability.
This is the link for colab: colab