Machine Learning on the Iris dataset

Machine Learning on the Iris dataset is quite easier than other datasets that are available on the Internet. Let’s learn with examples.

We use the Iris dataset as a supervised learning problem. 

Because in this case, the prediction of the species of an iris using the measurements is easy.

We have seen a few examples in our previous section.

We can load the Iris datasets in many ways.

However, in the first case, we have imported it with the scikit-learn library. 

# importing directly from scikit-learn toy datasets
from sklearn.datasets import load_iris

# we will learn what is "bunch" object cwhich is ontaining iris dataset and its attributes
iris_data_set = load_iris()
type(iris_data_set)

# output
sklearn.utils.Bunch

Next we have saved the dataset object to a variable.

iris_data_set = load_iris()

Now we can print out the whole dataset and get the idea. As we did before in our previous section.

And after that we can see how many rows there are and how many columns there are.

# get the number of rows and columns
print(iris_data_set.data.shape)

# output
(150, 4)

Therefore the rows are the first dimension and the columns are the second dimension.

If we want to predict something, we call it a response and in machine learning terms it is the target.

# get the target only
print(iris_data_set.target.shape)

# output
(150,)

Basically when we see the data it looks as a two dimensional array. A table with columns and rows.

Second Data table form Iris datasets
Second Data table form Iris datasets

As a whole we call it features. 

Consequently we can separate the features and target and point them to the two separate variables as below.

# X represents features
X = iris_data_set.data

# y represents target
y = iris_data_set.target

print(X)
print(y)

As expected the output is quite big, because the features matrix and the response vector are two separate objects. 

With reference to the Iris dataset, we can handle the same dataset in several different ways. 

In the next section, we will see how we can handle it with the Pandas and seaborn library.

Before digging deeper, we can have a look at the different types of data visualization.

Iris dataset visualisation with seaborn and Pandas library
Iris dataset visualisation with seaborn and Pandas library

For more such examples please visit the respective branch of the GitHub Repository.

In the next section we will discuss it. Till then stay tuned, be happy and cheer up.

What Next?

Books at Leanpub

Books in Apress

My books at Amazon

GitHub repository

TensorFlow, Machine Learning, AI and Data Science

Flutter, Dart and Algorithm

C, C++, Java and Game Development

Twitter

Comments

Leave a Reply