Finding out the type of Iris Flowers using iris dataset💢

Saksham Awasthi
5 min readJul 30, 2021

So, in this, we are going to make a simple and beginner-friendly program to find out the type of iris by the given data.

Firstly what is Iris?
So it is a Victorian-era language of flowers that gives a host of meanings to iris flowers. They can represent faith, hope, courage, wisdom, and admiration.

Now we have this iris dataset, quite famous when someone is diving into or touching the surface of Machine Learning. So we can easily make it happen .
This requires or we can say have into it the classification. The classification and regression differ as that regression says: What is this ?, whereas classification says What is this among these(Like a MCQ question).

So we should open our pyCharm or any other (Democratic internet).

Firstly we have to import our dataset from the sklearn , if we have to import data from the original site, It would be very much of a headache So sklearn has simplified this for us.
So we can simply import the iris dataset from sklearn (So now we have to convert this factor into code)

Now by writing this line we have imported all the datasets that sklearn provides.
Now, we have to make this dataset only for the iris one. So we can simply devote the iris dataset to a variable. In this case, we have given a variable named iris and allotted the iris dataset to it.

By doing this we have assigned the dataset to the iris variable , for seeing what is inside this dataset we can simply do

and we get the output as::

Iris plants dataset
— — — — — — — — — —

**Data Set Characteristics:**

:Number of Instances: 150 (50 in each of three classes)
:Number of Attributes: 4 numeric, predictive attributes and the class
:Attribute Information:
— sepal length in cm
— sepal width in cm
— petal length in cm
— petal width in cm
— class:
— Iris-Setosa
— Iris-Versicolour
— Iris-Virginica

:Summary Statistics:

============== ==== ==== ======= ===== ====================
Min Max Mean SD Class Correlation
============== ==== ==== ======= ===== ====================
sepal length: 4.3 7.9 5.84 0.83 0.7826
sepal width: 2.0 4.4 3.05 0.43 -0.4194
petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)
petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)
============== ==== ==== ======= ===== ====================

:Missing Attribute Values: None
:Class Distribution: 33.3% for each of 3 classes.
:Creator: R.A. Fisher
:Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
:Date: July, 1988

The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken
from Fisher’s paper. Note that it’s the same as in R, but not as in the UCI
Machine Learning Repository, which has two wrong data points.

This is perhaps the best known database to be found in the
pattern recognition literature. Fisher’s paper is a classic in the field and
is referenced frequently to this day. (See Duda & Hart, for example.) The
data set contains 3 classes of 50 instances each, where each class refers to a
type of iris plant. One class is linearly separable from the other 2; the
latter are NOT linearly separable from each other.

.. topic:: References

- Fisher, R.A. “The use of multiple measurements in taxonomic problems”
Annual Eugenics, 7, Part II, 179–188 (1936); also in “Contributions to
Mathematical Statistics” (John Wiley, NY, 1950).
— Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.
(Q327.D83) John Wiley & Sons. ISBN 0–471–22361–1. See page 218.
— Dasarathy, B.V. (1980) “Nosing Around the Neighborhood: A New System
Structure and Classification Rule for Recognition in Partially Exposed
Environments”. IEEE Transactions on Pattern Analysis and Machine
Intelligence, Vol. PAMI-2, №1, 67–71.
— Gates, G.W. (1972) “The Reduced Nearest Neighbor Rule”. IEEE Transactions
on Information Theory, May 1972, 431–433.
— See also: 1988 MLC Proceedings, 54–64. Cheeseman et al”s AUTOCLASS II
conceptual clustering system finds 3 classes in the data.
— Many, many more …

now we can simply assign the data to the variables.

Now , the second thing is the labels.

Now, we can make a classifier that is already present in sklearn.neighbors i.e, KNeighborsClassifier so we can simply assign or plot a classifier in it.

Importing KNeigborsClassifier

Now, in this classifier, we have to fit the data which is to be trained. So, the features variable which we created which stores data is the first key, and the label one is the second key.

Now we have plotted or trained this classifier. Now to see the result of that by simply doing prediction.

The output is 0 so we can simply say that the flower is setosa.

By changing the arrays we can simply see the output. And if we are confused that what denotes what then simply use DESCR fun() for fun 😂.

The code if you are not able to understand the stuff ::

from sklearn import datasets
from sklearn.neighbors import KNeighborsClassifier
#importing data
iris = datasets.load_iris()
#loading data
print(iris.DESCR)
#describing features and abouts of the data
features = iris.data
# data catches features i.e, main content of the data
label = iris.target
#the labels i.e, value to be targetted

# print("features::",features[0])
# print("target",label[0])

clf = KNeighborsClassifier()
clf.fit(features,label)
# updated the value in the classifier of clf by using fit

pred = clf.predict([[1,1,1,1]])
print(pred)

--

--