This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_labels[0] | |
# 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np.argmax(predictions[0]) | |
# 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
predictions[0] | |
''' | |
array([2.9212106e-07, 1.6208847e-10, 1.3363140e-08, 2.7341349e-09, | |
5.5379962e-10, 4.5457238e-04, 4.2226111e-06, 4.4925120e-03, | |
5.8868943e-07, 9.9504781e-01], dtype=float32) | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
probability_model = tf.keras.Sequential([model, | |
tf.keras.layers.Softmax()]) | |
predictions = probability_model.predict(test_images) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2) | |
print('\nTest accuracy:', test_acc) | |
''' | |
313/313 - 0s - loss: 0.3413 - accuracy: 0.8814 | |
Test accuracy: 0.8813999891281128 ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.fit(train_images, train_labels, epochs=10) | |
''' | |
Epoch 1/10 | |
1875/1875 [==============================] - 3s 1ms/step - loss: 0.4982 - accuracy: 0.8256 | |
Epoch 2/10 | |
1875/1875 [==============================] - 3s 1ms/step - loss: 0.3747 - accuracy: 0.8658 | |
Epoch 3/10 | |
1875/1875 [==============================] - 3s 1ms/step - loss: 0.3356 - accuracy: 0.8770 | |
Epoch 4/10 | |
1875/1875 [==============================] - 3s 1ms/step - loss: 0.3112 - accuracy: 0.8856 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.compile(optimizer='adam', | |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), | |
metrics=['accuracy']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = tf.keras.Sequential([ | |
tf.keras.layers.Flatten(input_shape=(28, 28)), | |
tf.keras.layers.Dense(128, activation='relu'), | |
tf.keras.layers.Dense(10) | |
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plt.figure(figsize=(10,10)) | |
for i in range(25): | |
plt.subplot(5,5,i+1) | |
plt.xticks([]) | |
plt.yticks([]) | |
plt.grid(False) | |
plt.imshow(train_images[i], cmap=plt.cm.binary) | |
plt.xlabel(class_names[train_labels[i]]) | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_images = train_images / 255.0 | |
test_images = test_images / 255.0 |