Classifying iris species using logistic regression
Another famous dataset in the world of machine learning is called the Iris dataset. The Iris dataset contains measurements of 150 iris flowers from three different species: setosa, versicolor, and viriginica. These measurements include the length and width of the petals, and the length and width of the sepals, all measured in centimeters:

An iris flower
Our goal is to build a machine learning model that can learn the measurements of these iris flowers, whose species are known, so that we can predict the species for a new iris flower.
Understanding logistic regression
Despite its name, logistic regression can actually be used as a model for classification. It uses a logistic function (or sigmoid) to convert any real-valued input x into a predicted output value ŷ that takes values between 0 and 1, as shown in the following figure:

The logistic function
Rounding ŷ to the nearest integer effectively classifies the input as belonging either to class...