|
195 | 195 | "* Iris virginica\n",
|
196 | 196 | "* Iris versicolor\n",
|
197 | 197 | "\n",
|
198 |
| - "<figure>\n", |
199 |
| - " <img src=\"https://www.tensorflow.org/images/iris_three_species.jpg\"\n", |
200 |
| - " alt=\"Petal geometry compared for three iris species: Iris setosa, Iris virginica, and Iris versicolor\">\n", |
201 |
| - " <figcaption>\n", |
202 |
| - " **Figure 1.** [Iris setosa](https://commons.wikimedia.org/w/index.php?curid=170298) (by [Radomil](https://commons.wikimedia.org/wiki/User:Radomil), CC BY-SA 3.0), [Iris versicolor](https://commons.wikimedia.org/w/index.php?curid=248095) (by [Dlanglois](https://commons.wikimedia.org/wiki/User:Dlanglois), CC BY-SA 3.0), and [Iris virginica](https://www.flickr.com/photos/33397993@N05/3352169862) (by [Frank Mayfield](https://www.flickr.com/photos/33397993@N05), CC BY-SA 2.0).\n", |
203 |
| - " </figcaption>\n", |
204 |
| - "</figure>\n", |
| 198 | + "<table>\n", |
| 199 | + " <tr><td>\n", |
| 200 | + " <img src=\"https://www.tensorflow.org/images/iris_three_species.jpg\"\n", |
| 201 | + " alt=\"Petal geometry compared for three iris species: Iris setosa, Iris virginica, and Iris versicolor\">\n", |
| 202 | + " </td></tr>\n", |
| 203 | + " <tr><td align=\"center\">\n", |
| 204 | + " <b>Figure 1.</b> <a href=\"https://commons.wikimedia.org/w/index.php?curid=170298\">Iris setosa</a> (by <a href=\"https://commons.wikimedia.org/wiki/User:Radomil\">Radomil</a>, CC BY-SA 3.0), <a href=\"https://commons.wikimedia.org/w/index.php?curid=248095\">Iris versicolor</a>, (by <a href=\"https://commons.wikimedia.org/wiki/User:Dlanglois\">Dlanglois</a>, CC BY-SA 3.0), and <a href=\"https://www.flickr.com/photos/33397993@N05/3352169862\">Iris virginica</a> (by <a href=\"https://www.flickr.com/photos/33397993@N05\">Frank Mayfield</a>, CC BY-SA 2.0).<br/> \n", |
| 205 | + " </td></tr>\n", |
| 206 | + "</table>\n", |
205 | 207 | "\n",
|
206 | 208 | "Fortunately, someone has already created a [data set of 120 Iris flowers](https://en.wikipedia.org/wiki/Iris_flower_data_set) with the sepal and petal measurements. This is a classic dataset that is popular for beginner machine learning classification problems."
|
207 | 209 | ]
|
|
398 | 400 | "\n",
|
399 | 401 | "We need to select the kind of model to train. There are many types of models and picking a good one takes experience. This tutorial uses a neural network to solve the Iris classification problem. *[Neural networks](https://developers.google.com/machine-learning/glossary/#neural_network)* can find complex relationships between features and the label. It is a highly-structured graph, organized into one or more *[hidden layers](https://developers.google.com/machine-learning/glossary/#hidden_layer)*. Each hidden layer consists of one or more *[neurons](https://developers.google.com/machine-learning/glossary/#neuron)*. There are several categories of neural networks and this program uses a dense, or *[fully-connected neural network](https://developers.google.com/machine-learning/glossary/#fully_connected_layer)*: the neurons in one layer receive input connections from *every* neuron in the previous layer. For example, Figure 2 illustrates a dense neural network consisting of an input layer, two hidden layers, and an output layer:\n",
|
400 | 402 | "\n",
|
401 |
| - "<figure>\n", |
402 |
| - " <img src=\"https://www.tensorflow.org/images/custom_estimators/full_network.png\"\n", |
403 |
| - " alt=\"A diagram of the network architecture: Inputs, 2 hidden layers, and outputs\">\n", |
404 |
| - " <figcaption>\n", |
405 |
| - " **Figure 2.** A neural network with features, hidden layers, and predictions.\n", |
406 |
| - " </figcaption>\n", |
407 |
| - "</figure>\n", |
| 403 | + "<table>\n", |
| 404 | + " <tr><td>\n", |
| 405 | + " <img src=\"https://www.tensorflow.org/images/custom_estimators/full_network.png\"\n", |
| 406 | + " alt=\"A diagram of the network architecture: Inputs, 2 hidden layers, and outputs\">\n", |
| 407 | + " </td></tr>\n", |
| 408 | + " <tr><td align=\"center\">\n", |
| 409 | + " <b>Figure 2.</b> A neural network with features, hidden layers, and predictions.<br/> \n", |
| 410 | + " </td></tr>\n", |
| 411 | + "</table>\n", |
408 | 412 | "\n",
|
409 | 413 | "When the model from Figure 2 is trained and fed an unlabeled example, it yields three predictions: the likelihood that this flower is the given Iris species. This prediction is called *[inference](https://developers.google.com/machine-learning/crash-course/glossary#inference)*. For this example, the sum of the output predictions are 1.0. In Figure 2, this prediction breaks down as: `0.03` for *Iris setosa*, `0.95` for *Iris versicolor*, and `0.02` for *Iris virginica*. This means that the model predicts—with 95% probability—that an unlabeled example flower is an *Iris versicolor*."
|
410 | 414 | ]
|
|
532 | 536 | "\n",
|
533 | 537 | "An *[optimizer](https://developers.google.com/machine-learning/crash-course/glossary#optimizer)* applies the computed gradients to the model's variables to minimize the `loss` function. You can think of a curved surface (see Figure 3) and we want to find its lowest point by walking around. The gradients point in the direction of steepest the ascent—so we'll travel the opposite way and move down the hill. By iteratively calculating the loss and gradients for each *step* (or *[learning rate](https://developers.google.com/machine-learning/crash-course/glossary#learning_rate)*), we'll adjust the model during training. Gradually, the model will find the best combination of weights and bias to minimize loss. And the lower the loss, the better the model's predictions.\n",
|
534 | 538 | "\n",
|
535 |
| - "<figure>\n", |
536 |
| - " <img src=\"http://cs231n.github.io/assets/nn3/opt1.gif\" alt=\"\" width=\"45%\">\n", |
537 |
| - " <figcaption>\n", |
538 |
| - " **Figure 3.** Optimization algorthims visualized over time in 3D space. (Source: [Stanford class CS231n](http://cs231n.github.io/neural-networks-3/), MIT License)\n", |
539 |
| - " </figcaption>\n", |
540 |
| - "</figure>\n", |
| 539 | + "<table>\n", |
| 540 | + " <tr><td>\n", |
| 541 | + " <img src=\"http://cs231n.github.io/assets/nn3/opt1.gif\" width=\"70%\"\n", |
| 542 | + " alt=\"Optimization algorthims visualized over time in 3D space.\">\n", |
| 543 | + " </td></tr>\n", |
| 544 | + " <tr><td align=\"center\">\n", |
| 545 | + " <b>Figure 3.</b> Optimization algorthims visualized over time in 3D space. (Source: <a href=\"http://cs231n.github.io/neural-networks-3/\">Stanford class CS231n</a>, MIT License)<br/> \n", |
| 546 | + " </td></tr>\n", |
| 547 | + "</table>\n", |
541 | 548 | "\n",
|
542 | 549 | "TensorFlow has many [optimization algorithms](https://www.tensorflow.org/api_guides/python/train) available for training. This model uses the [tf.train.GradientDescentOptimizer](https://www.tensorflow.org/api_docs/python/tf/train/GradientDescentOptimizer) that implements the *[standard gradient descent](https://developers.google.com/machine-learning/crash-course/glossary#gradient_descent)* (SGD) algorithm. The `learning_rate` sets the step size to take for each iteration down the hill. This is a *hyperparameter* that you'll commonly adjust to achieve better results."
|
543 | 550 | ]
|
|
693 | 700 | "\n",
|
694 | 701 | "*Evaluating* means determining how effectively the model makes predictions. To determine the model's effectiveness at Iris classification, pass some sepal and petal measurements to the model and ask the model to predict what Iris species they represent. Then compare the model's prediction against the actual label. For example, a model that picked the correct species on half the input examples has an *[accuracy](https://developers.google.com/machine-learning/glossary/#accuracy)* of `0.5`. Figure 4 shows a slightly more effective model, getting 4 out of 5 predictions correct at 80% accuracy:\n",
|
695 | 702 | "\n",
|
696 |
| - "<figure>\n", |
697 |
| - " <table cellpadding=\"8\" border=\"0\">\n", |
698 |
| - " <colgroup>\n", |
699 |
| - " <col span=\"4\" >\n", |
700 |
| - " <col span=\"1\" bgcolor=\"lightblue\">\n", |
701 |
| - " <col span=\"1\" bgcolor=\"lightgreen\">\n", |
702 |
| - " </colgroup>\n", |
703 |
| - " <tr bgcolor=\"lightgray\">\n", |
704 |
| - " <th colspan=\"4\">Example features</th>\n", |
705 |
| - " <th colspan=\"1\">Label</th>\n", |
706 |
| - " <th colspan=\"1\" >Model prediction</th>\n", |
707 |
| - " </tr>\n", |
708 |
| - " <tr>\n", |
709 |
| - " <td>5.9</td><td>3.0</td><td>4.3</td><td>1.5</td><td align=\"center\">1</td><td align=\"center\">1</td>\n", |
710 |
| - " </tr>\n", |
711 |
| - " <tr>\n", |
712 |
| - " <td>6.9</td><td>3.1</td><td>5.4</td><td>2.1</td><td align=\"center\">2</td><td align=\"center\">2</td>\n", |
713 |
| - " </tr>\n", |
714 |
| - " <tr>\n", |
715 |
| - " <td>5.1</td><td>3.3</td><td>1.7</td><td>0.5</td><td align=\"center\">0</td><td align=\"center\">0</td>\n", |
716 |
| - " </tr>\n", |
717 |
| - " <tr>\n", |
718 |
| - " <td>6.0</td> <td>3.4</td> <td>4.5</td> <td>1.6</td> <td align=\"center\">1</td><td align=\"center\" bgcolor=\"red\">2</td>\n", |
719 |
| - " </tr>\n", |
720 |
| - " <tr>\n", |
721 |
| - " <td>5.5</td><td>2.5</td><td>4.0</td><td>1.3</td><td align=\"center\">1</td><td align=\"center\">1</td>\n", |
722 |
| - " </tr>\n", |
723 |
| - " </table>\n", |
724 |
| - " <figcaption>**Figure 4.** An Iris classifier that is 80% accurate.</figcaption>\n", |
725 |
| - "</figure>" |
| 703 | + "<table cellpadding=\"8\" border=\"0\">\n", |
| 704 | + " <colgroup>\n", |
| 705 | + " <col span=\"4\" >\n", |
| 706 | + " <col span=\"1\" bgcolor=\"lightblue\">\n", |
| 707 | + " <col span=\"1\" bgcolor=\"lightgreen\">\n", |
| 708 | + " </colgroup>\n", |
| 709 | + " <tr bgcolor=\"lightgray\">\n", |
| 710 | + " <th colspan=\"4\">Example features</th>\n", |
| 711 | + " <th colspan=\"1\">Label</th>\n", |
| 712 | + " <th colspan=\"1\" >Model prediction</th>\n", |
| 713 | + " </tr>\n", |
| 714 | + " <tr>\n", |
| 715 | + " <td>5.9</td><td>3.0</td><td>4.3</td><td>1.5</td><td align=\"center\">1</td><td align=\"center\">1</td>\n", |
| 716 | + " </tr>\n", |
| 717 | + " <tr>\n", |
| 718 | + " <td>6.9</td><td>3.1</td><td>5.4</td><td>2.1</td><td align=\"center\">2</td><td align=\"center\">2</td>\n", |
| 719 | + " </tr>\n", |
| 720 | + " <tr>\n", |
| 721 | + " <td>5.1</td><td>3.3</td><td>1.7</td><td>0.5</td><td align=\"center\">0</td><td align=\"center\">0</td>\n", |
| 722 | + " </tr>\n", |
| 723 | + " <tr>\n", |
| 724 | + " <td>6.0</td> <td>3.4</td> <td>4.5</td> <td>1.6</td> <td align=\"center\">1</td><td align=\"center\" bgcolor=\"red\">2</td>\n", |
| 725 | + " </tr>\n", |
| 726 | + " <tr>\n", |
| 727 | + " <td>5.5</td><td>2.5</td><td>4.0</td><td>1.3</td><td align=\"center\">1</td><td align=\"center\">1</td>\n", |
| 728 | + " </tr>\n", |
| 729 | + " <tr><td align=\"center\" colspan=\"6\">\n", |
| 730 | + " <b>Figure 4.</b> An Iris classifier that is 80% accurate.<br/> \n", |
| 731 | + " </td></tr>\n", |
| 732 | + "</table>" |
726 | 733 | ]
|
727 | 734 | },
|
728 | 735 | {
|
|
734 | 741 | "source": [
|
735 | 742 | "### Setup the test dataset\n",
|
736 | 743 | "\n",
|
737 |
| - "Evaluating the model is similiar to training the model. The biggest difference is the examples come from a separate *[test set](https://developers.google.com/machine-learning/crash-course/glossary#test_set)* rather than the training set. To fairly assess a model's effectiveness, the examples used to evaluate a model must be different from the examples used to train the model.\n", |
| 744 | + "Evaluating the model is similar to training the model. The biggest difference is the examples come from a separate *[test set](https://developers.google.com/machine-learning/crash-course/glossary#test_set)* rather than the training set. To fairly assess a model's effectiveness, the examples used to evaluate a model must be different from the examples used to train the model.\n", |
738 | 745 | "\n",
|
739 |
| - "The setup for the test `Dataset` is similiar to the setup for training `Dataset`. Download the CSV text file and parse that values, then give it a little shuffle:" |
| 746 | + "The setup for the test `Dataset` is similar to the setup for training `Dataset`. Download the CSV text file and parse that values, then give it a little shuffle:" |
740 | 747 | ]
|
741 | 748 | },
|
742 | 749 | {
|
|
0 commit comments