Commit 8cbdb869 authored by Mark Daoust's avatar Mark Daoust
Browse files

minor cleanup

parent fbe06895
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
"colab": { "colab": {
"name": "basic_classification.ipynb", "name": "basic_classification.ipynb",
"version": "0.3.2", "version": "0.3.2",
"views": {},
"default_view": {},
"provenance": [], "provenance": [],
"private_outputs": true, "private_outputs": true,
"collapsed_sections": [], "collapsed_sections": [],
...@@ -32,12 +30,7 @@ ...@@ -32,12 +30,7 @@
"metadata": { "metadata": {
"id": "_ckMIh7O7s6D", "id": "_ckMIh7O7s6D",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {},
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"cellView": "form" "cellView": "form"
}, },
"cell_type": "code", "cell_type": "code",
...@@ -61,12 +54,7 @@ ...@@ -61,12 +54,7 @@
"metadata": { "metadata": {
"id": "vasWnqRgy1H4", "id": "vasWnqRgy1H4",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {},
"autoexec": {
"startup": false,
"wait_interval": 0
}
},
"cellView": "form" "cellView": "form"
}, },
"cell_type": "code", "cell_type": "code",
...@@ -142,12 +130,7 @@ ...@@ -142,12 +130,7 @@
"metadata": { "metadata": {
"id": "dzLKpmZICaWN", "id": "dzLKpmZICaWN",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -204,12 +187,7 @@ ...@@ -204,12 +187,7 @@
"metadata": { "metadata": {
"id": "7MqDQO0KCaWS", "id": "7MqDQO0KCaWS",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -288,12 +266,7 @@ ...@@ -288,12 +266,7 @@
"metadata": { "metadata": {
"id": "IjnLH5S2CaWx", "id": "IjnLH5S2CaWx",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -319,12 +292,7 @@ ...@@ -319,12 +292,7 @@
"metadata": { "metadata": {
"id": "zW5k_xz1CaWX", "id": "zW5k_xz1CaWX",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -347,12 +315,7 @@ ...@@ -347,12 +315,7 @@
"metadata": { "metadata": {
"id": "TRFYHB2mCaWb", "id": "TRFYHB2mCaWb",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -375,12 +338,7 @@ ...@@ -375,12 +338,7 @@
"metadata": { "metadata": {
"id": "XKnCTHz4CaWg", "id": "XKnCTHz4CaWg",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -403,12 +361,7 @@ ...@@ -403,12 +361,7 @@
"metadata": { "metadata": {
"id": "2KFnYlcwCaWl", "id": "2KFnYlcwCaWl",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -431,12 +384,7 @@ ...@@ -431,12 +384,7 @@
"metadata": { "metadata": {
"id": "iJmPr5-ACaWn", "id": "iJmPr5-ACaWn",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -461,19 +409,14 @@ ...@@ -461,19 +409,14 @@
"metadata": { "metadata": {
"id": "m4VEw8Ud9Quh", "id": "m4VEw8Ud9Quh",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"plt.figure()\n", "plt.figure()\n",
"plt.imshow(train_images[0])\n", "plt.imshow(train_images[0])\n",
"plt.colorbar()\n", "plt.colorbar()\n",
"plt.gca().grid(False)" "plt.grid('off')"
], ],
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
...@@ -502,12 +445,7 @@ ...@@ -502,12 +445,7 @@
"metadata": { "metadata": {
"id": "bW5WzIPlCaWv", "id": "bW5WzIPlCaWv",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -532,12 +470,7 @@ ...@@ -532,12 +470,7 @@
"metadata": { "metadata": {
"id": "oZTImqg_CaW1", "id": "oZTImqg_CaW1",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -583,12 +516,7 @@ ...@@ -583,12 +516,7 @@
"metadata": { "metadata": {
"id": "9ODch-OFCaW4", "id": "9ODch-OFCaW4",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -625,12 +553,7 @@ ...@@ -625,12 +553,7 @@
"metadata": { "metadata": {
"id": "Lhan11blCaW7", "id": "Lhan11blCaW7",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -663,12 +586,7 @@ ...@@ -663,12 +586,7 @@
"metadata": { "metadata": {
"id": "xvwvpA64CaW_", "id": "xvwvpA64CaW_",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -703,12 +621,7 @@ ...@@ -703,12 +621,7 @@
"metadata": { "metadata": {
"id": "VflXLEeECaXC", "id": "VflXLEeECaXC",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -745,12 +658,7 @@ ...@@ -745,12 +658,7 @@
"metadata": { "metadata": {
"id": "Gl91RPhdCaXI", "id": "Gl91RPhdCaXI",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -773,12 +681,7 @@ ...@@ -773,12 +681,7 @@
"metadata": { "metadata": {
"id": "3DmJEUinCaXK", "id": "3DmJEUinCaXK",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -801,12 +704,7 @@ ...@@ -801,12 +704,7 @@
"metadata": { "metadata": {
"id": "qsqenuPnCaXO", "id": "qsqenuPnCaXO",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -829,12 +727,7 @@ ...@@ -829,12 +727,7 @@
"metadata": { "metadata": {
"id": "Sd7Pgsu6CaXP", "id": "Sd7Pgsu6CaXP",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -843,7 +736,7 @@ ...@@ -843,7 +736,7 @@
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
}, },
{ {
"metadata": { "metadata": {
"id": "ygh2yYC972ne", "id": "ygh2yYC972ne",
"colab_type": "text" "colab_type": "text"
...@@ -861,10 +754,12 @@ ...@@ -861,10 +754,12 @@
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"def plot_image(predictions_array, true_label, img):\n", "def plot_image(i, predictions_array, true_label, img):\n",
" predictions_array, true_label, img = predictions_array[i], true_label[i], img[i]\n",
" plt.grid('off')\n",
" plt.xticks([])\n", " plt.xticks([])\n",
" plt.yticks([])\n", " plt.yticks([])\n",
" plt.grid('off')\n", " \n",
" plt.imshow(img, cmap=plt.cm.binary)\n", " plt.imshow(img, cmap=plt.cm.binary)\n",
"\n", "\n",
" predicted_label = np.argmax(predictions_array)\n", " predicted_label = np.argmax(predictions_array)\n",
...@@ -872,12 +767,14 @@ ...@@ -872,12 +767,14 @@
" color = 'blue'\n", " color = 'blue'\n",
" else:\n", " else:\n",
" color = 'red'\n", " color = 'red'\n",
" plt.xlabel(\"{} {} ({})\".format(class_names[predicted_label],\n", " \n",
" str(round(predictions_array[np.argmax(predictions_array)] * 100)) + \"%\",\n", " plt.xlabel(\"{} {:2.0f}% ({})\".format(class_names[predicted_label],\n",
" 100*np.max(predictions_array),\n",
" class_names[true_label]),\n", " class_names[true_label]),\n",
" color=color)\n", " color=color)\n",
"\n", "\n",
"def plot_value_array(predictions_array, true_label):\n", "def plot_value_array(i, predictions_array, true_label):\n",
" predictions_array, true_label = predictions_array[i], true_label[i]\n",
" plt.grid('off')\n", " plt.grid('off')\n",
" plt.xticks([])\n", " plt.xticks([])\n",
" plt.yticks([])\n", " plt.yticks([])\n",
...@@ -886,20 +783,7 @@ ...@@ -886,20 +783,7 @@
" predicted_label = np.argmax(predictions_array)\n", " predicted_label = np.argmax(predictions_array)\n",
" \n", " \n",
" thisplot[predicted_label].set_color('red')\n", " thisplot[predicted_label].set_color('red')\n",
" thisplot[true_label].set_color('blue')\n", " thisplot[true_label].set_color('blue')"
"\n",
" \n",
"# define plot to look at the image, predicted label, actual label, predicted percent for top prediction, and graph of all prediction values\n",
"def plot_fig_and_predarray(iter):\n",
" plt.figure(figsize=(6,3))\n",
" \n",
" # plot the image first\n",
" plt.subplot(1,2,1)\n",
" plot_image(predictions[iter], test_labels[iter], test_images[int(iter)])\n",
" \n",
" # then the graph of 10 values\n",
" plt.subplot(1,2,2)\n",
" plot_value_array(predictions[iter], test_labels[iter])"
], ],
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
...@@ -922,7 +806,12 @@ ...@@ -922,7 +806,12 @@
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"plot_fig_and_predarray(0)" "i = 0\n",
"plt.figure(figsize=(6,3))\n",
"plt.subplot(1,2,1)\n",
"plot_image(i, predictions, test_labels, test_images)\n",
"plt.subplot(1,2,2)\n",
"plot_value_array(i, predictions, test_labels)"
], ],
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
...@@ -935,7 +824,12 @@ ...@@ -935,7 +824,12 @@
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"plot_fig_and_predarray(12)" "i = 12\n",
"plt.figure(figsize=(6,3))\n",
"plt.subplot(1,2,1)\n",
"plot_image(i, predictions, test_labels, test_images)\n",
"plt.subplot(1,2,2)\n",
"plot_value_array(i, predictions, test_labels)"
], ],
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
...@@ -966,9 +860,9 @@ ...@@ -966,9 +860,9 @@
"plt.figure(figsize=(2*2*num_cols, 2*num_rows))\n", "plt.figure(figsize=(2*2*num_cols, 2*num_rows))\n",
"for i in range(num_images):\n", "for i in range(num_images):\n",
" plt.subplot(num_rows, 2*num_cols, 2*i+1)\n", " plt.subplot(num_rows, 2*num_cols, 2*i+1)\n",
" plot_image(predictions[i], test_labels[i], test_images[i])\n", " plot_image(i, predictions, test_labels, test_images)\n",
" plt.subplot(num_rows, 2*num_cols, 2*i+2)\n", " plt.subplot(num_rows, 2*num_cols, 2*i+2)\n",
" plot_value_array(predictions[i], test_labels[i])\n" " plot_value_array(i, predictions, test_labels)\n"
], ],
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
...@@ -1050,6 +944,20 @@ ...@@ -1050,6 +944,20 @@
"execution_count": 0, "execution_count": 0,
"outputs": [] "outputs": []
}, },
{
"metadata": {
"id": "6Ai-cpLjO-3A",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"plot_value_array(0, predictions_single, test_labels)\n",
"_ = plt.xticks(range(10), class_names, rotation=45)"
],
"execution_count": 0,
"outputs": []
},
{ {
"metadata": { "metadata": {
"id": "cU1Y2OAMCaXb", "id": "cU1Y2OAMCaXb",
...@@ -1084,4 +992,4 @@ ...@@ -1084,4 +992,4 @@
] ]
} }
] ]
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment