<jupyter_start><jupyter_text>Toy example: Fitting a linear function with neural networks- We want to fit data from the function y=2x-1- Using a NN with only one layer and one unit- Using SGD and mean squared error- Training for 200 epochs<jupyter_code>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')
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)
model.fit(xs, ys, epochs=200)
print(model.predict([10.0]))<jupyter_output>[[18.451828]]