Import the libraries

In [1]:
import tensorflow as tf
import numpy as np

Get the training data

In [2]:
x = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0])
y = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0])

Build the neural network

In [3]:
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(units=1, input_shape=[1]))
model.summary()
Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense (Dense)                (None, 1)                 2         
=================================================================
Total params: 2
Trainable params: 2
Non-trainable params: 0
_________________________________________________________________

Choose Loss function and Optimizer

In [4]:
model.compile(optimizer='sgd', loss='mean_squared_error')

Start the learning process

In [ ]:
model.fit(x, y, epochs=500)

Make some predictions

In [6]:
values = np.array([10.0])

predictions = model.predict(values)

print(predictions)
[[18.985792]]