Chapter04 - Getting Started With Neural Networks
Chapter04 - Getting Started With Neural Networks
For
readability, it only contains runnable code blocks and section titles, and omits everything
else in the book: text paragraphs, figures, and pseudocode.
If you want to be able to follow what's going on, I recommend reading the notebook
side by side with your copy of the book.
This notebook was generated for TensorFlow 2.6.
train_data[0]
train_labels[0]
x_train[0]
y_train = np.asarray(train_labels).astype("float32")
y_test = np.asarray(test_labels).astype("float32")
model = keras.Sequential([
layers.Dense(16, activation="relu"),
layers.Dense(16, activation="relu"),
layers.Dense(1, activation="sigmoid")
])
history_dict = history.history
history_dict.keys()
results
Further experiments
Wrapping up
len(train_data)
len(test_data)
train_data[10]
train_labels[10]
results
import copy
test_labels_copy = copy.copy(test_labels)
np.random.shuffle(test_labels_copy)
hits_array = np.array(test_labels) == np.array(test_labels_copy)
hits_array.mean()
predictions[0].shape
np.sum(predictions[0])
np.argmax(predictions[0])
model.compile(optimizer="rmsprop",
loss="sparse_categorical_crossentropy",
metrics=["accuracy"])
Wrapping up
train_data.shape
test_data.shape
train_targets
all_scores
np.mean(all_scores)
test_mae_score
Wrapping up
Summary