# on 28-Apr-2024 (Sun)

#### Flashcard 7624069090572

Tags
#tensorflow #tensorflow-certificate
Question

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
import numpy as np

model = Sequential(Dense(1, input_shape=[1]))
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([1,5,12,-1,10], dtype=float)
ys = np.array([5,13,27,1,23], dtype=float)
model.fit([...], epochs=500)
model.predict(x=[15])

xs, ys

status measured difficulty not learned 37% [default] 0

Tensorflow basics - typical flow of model building
= Sequential(Dense(1, input_shape=[1])) model.compile(optimizer='sgd', loss='mean_squared_error') xs = np.array([1,5,12,-1,10], dtype=float) ys = np.array([5,13,27,1,23], dtype=float) model.fit(<span>xs, ys, epochs=500) model.predict(x=[15]) <span>

#### Flashcard 7624072236300

Tags
#tensorflow #tensorflow-certificate
Question

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
import numpy as np

model = Sequential(Dense(1, [...]=[1]))
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([1,5,12,-1,10], dtype=float)
ys = np.array([5,13,27,1,23], dtype=float)
model.fit(xs, ys, epochs=500)
model.predict(x=[15])

input_shape

status measured difficulty not learned 37% [default] 0

Tensorflow basics - typical flow of model building
from tensorflow.keras import Sequential from tensorflow.keras.layers import Dense import numpy as np model = Sequential(Dense(1, input_shape=[1])) model.compile(optimizer='sgd', loss='mean_squared_error') xs = np.array([1,5,12,-1,10], dtype=float) ys = np.array([5,13,27,1,23], dtype=float) model.fit(xs, ys, epochs=500) model

#### Flashcard 7624088227084

Tags
#tensorflow #tensorflow-certificate
Question

import tensorflow as tf

#stop training after reaching accuract of 0.99
class MyCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if logs.[...]('accuracy')>=0.99:
print('\nAccuracy 0.99 achieved')
self.model.stop_training = True


get

status measured difficulty not learned 37% [default] 0

Tensorflow - callbacks
import tensorflow as tf #stop training after reaching accuract of 0.99 class MyCallback(tf.keras.callbacks.Callback): def on_epoch_end(self, epoch, logs={}): if logs.get('accuracy')>=0.99: print('\nAccuracy 0.99 achieved') self.model.stop_training = True

#### Flashcard 7625619410188

Tags
#tensorflow #tensorflow-certificate
Question
y_test.shape, y_pred.shape, y_pred.[...]((10, )).shape, tf.squeeze(y_pred).shape

(TensorShape([10]), (10, 1), (10,), TensorShape([10]))

reshape

status measured difficulty not learned 37% [default] 0

Different shapes of the tensors
y_test.shape, y_pred.shape, y_pred.reshape((10, )).shape, tf.squeeze(y_pred).shape (TensorShape([10]), (10, 1), (10,), TensorShape([10]))

#### Flashcard 7625628323084

Tags
#tensorflow #tensorflow-certificate
Question
# Calculate MSE "by hand" in steps - identify functions

abs_err = [...](tf.subtract(tf.cast(y_test, dtype=tf.float32), tf.squeeze(y_pred)))
sq_abs_err = tf.multiply(abs_err, abs_err)
sq_abs_err
tf.math.reduce_mean(sq_abs_err)

<tf.Tensor: shape=(), dtype=float32, numpy=155.11417>

tf.abs

status measured difficulty not learned 37% [default] 0

Calculate MSE &quot;by hand&quot; in steps - identify functions
# Calculate MSE "by hand" in steps - identify functions abs_err = tf.abs(tf.subtract(tf.cast(y_test, dtype=tf.float32), tf.squeeze(y_pred))) sq_abs_err = tf.multiply(abs_err, abs_err) sq_abs_err tf.math.reduce_mean(sq_abs_err) <tf.Tensor: shape=(), dtype=

#### Flashcard 7625643265292

Tags
#has-images #tensorflow #tensorflow-certificate
[unknown IMAGE 7625638546700]
Question
[...](model_2, show_shapes=True)

plot_model

status measured difficulty not learned 37% [default] 0

Visualize model
plot_model(model_2, show_shapes=True)

#### Flashcard 7625690713356

Tags
#tensorflow #tensorflow-certificate
Question
tf.ones([10, 7])

<tf.Tensor: shape=(10, 7), dtype=float32, numpy=
array([[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1., 1.]], dtype=[...])>