Introduction to TensorFlow W1:A New Programming Paradigm

by Laurence Moroney

Code
import tensorflow as tf
import numpy as np
from tensorflow import keras

print(tf.__version__)
2.16.1
Code
# Build a simple Sequential model
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
Code
# Compile the model
model.compile(optimizer='sgd', loss='mean_squared_error')
Code
# Declare model inputs and outputs for training
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)
Code
# Train the model
model.fit(xs, ys, epochs=500,verbose=0)
<keras.src.callbacks.history.History at 0x2848f63d0>
Code
# Make a prediction
print(model.predict(x=np.array([10.0])))
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 13ms/step1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 13ms/step
[[18.976614]]

1 resource:

https://www.coursera.org/learn/introduction-tensorflow/home/info

https://github.com/https-deeplearning-ai/tensorflow-1-public/tree/main/C1

Back to top