Skip to content

Commit efc6c98

Browse files
authored
Exercise MicrosoftDocs#8: 'acc' key should be 'accuracy'
The snippet in exercise MicrosoftDocs#8 is trying to access the key 'acc' that doesn't exist in keras.models.Sequential().fit(...).history. It should be accessing 'accuracy' instead.
1 parent efc4ff6 commit efc6c98

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

08. Neural Networks Introduction - Python.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"trusted": true
8383
},
8484
"cell_type": "code",
85-
"source": "# Let's compile the model\n\n###\n# REPLACE THE <addLoss> WITH 'categorical_crossentropy', <addOptimizer> WITH 'sgd', AND <addMetric> with 'accuracy' (INCLUDING THE QUOTES)\n###\nmodel.compile(loss = <addLoss>, optimizer = <addOptimizer>, metrics = [<addMetric>])\n###\n\n# Time to fit the model\nprint('Starting training')\n\n###\n# REPLACE THE <addTrainX> WITH train_X AND <addTrainY> WITH train_Y\n###\ntraining_stats = model.fit(<addTrainX>, <addTrainY>, batch_size = 1, epochs = 24, verbose = 0)\n###\n\nprint('Training finished')\nprint('Training Evaluation: loss = %0.3f, accuracy = %0.2f%%'\n %(training_stats.history['loss'][-1], 100 * training_stats.history['acc'][-1]))",
85+
"source": "# Let's compile the model\n\n###\n# REPLACE THE <addLoss> WITH 'categorical_crossentropy', <addOptimizer> WITH 'sgd', AND <addMetric> with 'accuracy' (INCLUDING THE QUOTES)\n###\nmodel.compile(loss = <addLoss>, optimizer = <addOptimizer>, metrics = [<addMetric>])\n###\n\n# Time to fit the model\nprint('Starting training')\n\n###\n# REPLACE THE <addTrainX> WITH train_X AND <addTrainY> WITH train_Y\n###\ntraining_stats = model.fit(<addTrainX>, <addTrainY>, batch_size = 1, epochs = 24, verbose = 0)\n###\n\nprint('Training finished')\nprint('Training Evaluation: loss = %0.3f, accuracy = %0.2f%%'\n %(training_stats.history['loss'][-1], 100 * training_stats.history['accuracy'][-1]))",
8686
"execution_count": null,
8787
"outputs": []
8888
},
@@ -96,7 +96,8 @@
9696
"trusted": true
9797
},
9898
"cell_type": "code",
99-
"source": "# Run this!\n\naccuracy, = graph.plot(training_stats.history['acc'],label = 'Accuracy')\ntraining_loss, = graph.plot(training_stats.history['loss'],label = 'Training Loss')\n\n\ngraph.legend(handles = [accuracy,training_loss])\nloss = np.array(training_stats.history['loss'])\nxp = np.linspace(0, loss.shape[0], 10 * loss.shape[0])\ngraph.plot(xp, np.full(xp.shape, 1), c = 'k', linestyle = ':', alpha = 0.5)\ngraph.plot(xp, np.full(xp.shape, 0), c = 'k', linestyle = ':', alpha = 0.5)\ngraph.show()",
99+
"source": "# Run this!\n\naccuracy, = graph.plot(training_stats.history['accuracy'],label = '
100+
uracy')\ntraining_loss, = graph.plot(training_stats.history['loss'],label = 'Training Loss')\n\n\ngraph.legend(handles = [accuracy,training_loss])\nloss = np.array(training_stats.history['loss'])\nxp = np.linspace(0, loss.shape[0], 10 * loss.shape[0])\ngraph.plot(xp, np.full(xp.shape, 1), c = 'k', linestyle = ':', alpha = 0.5)\ngraph.plot(xp, np.full(xp.shape, 0), c = 'k', linestyle = ':', alpha = 0.5)\ngraph.show()",
100101
"execution_count": null,
101102
"outputs": []
102103
},
@@ -188,4 +189,4 @@
188189
},
189190
"nbformat": 4,
190191
"nbformat_minor": 2
191-
}
192+
}

0 commit comments

Comments
 (0)