Overview and Implementation

Welcome to Unraveling Unsupervised Machine Learning, a course designed to assist you in exploring, understanding, and applying the principles of unsupervised machine learning. This course focuses on the application of clustering and dimensionality reduction techniques using the magnificence of the Iris flower dataset.

In this lesson, we will scrutinize this tempting dataset in detail, comprehend its innate structure and various features, and carry out a comprehensive visual data analysis using Python and some additional libraries. An understanding of your dataset, a critical first step in any machine learning project, equips you with a keen comprehension of your data, empowering you to make informed decisions regarding preprocessing techniques, model selection, and more.

Introduction to Iris Datasets

The Iris flower dataset has achieved high-flying status in the machine learning realm. Ingeniously simple yet very informative, it has earned its stripes as one of the most popular datasets among the machine learning community. Compiled from a range of samples from each of three species of Iris flowers (Iris setosa, Iris virginica, and Iris versicolor), the dataset includes four cardinal measurements—the lengths and widths of the sepals and petals of each flower.

Let's dust off our coding hats and discuss how to load this dataset using Python's sklearn library. Our go-to for this task is the load_iris function from the sklearn.datasets module.

from sklearn.datasets import load_iris

iris = load_iris()
print(iris.data[:10])  # prints the first 10 samples
"""
[[5.1 3.5 1.4 0.2]
 [4.9 3.  1.4 0.2]
 [4.7 3.2 1.3 0.2]
 [4.6 3.1 1.5 0.2]
 [5.  3.6 1.4 0.2]
 [5.4 3.9 1.7 0.4]
 [4.6 3.4 1.4 0.3]
 [5.  3.4 1.5 0.2]
 [4.4 2.9 1.4 0.2]
 [4.9 3.1 1.5 0.1]]
"""

The output of the code above will show that each row of the output corresponds to an Iris flower (also known as a sample), and each column corresponds to a prominent feature measured from each flower.

Examining the Iris Datasets

The snapshot output from the previous section offers a sneak peek into the structure and arrangement of the dataset. However, we need to dig a little deeper to grasp the dataset's nuances.

The practical sklearn library extends several utility methods that allow us to examine the target variables and feature names. target, a key attribute of our iris object, gives a rundown of the species of each Iris in the dataset, and feature_names, another critical attribute, provides the names for each feature.

Below are examples of inspecting the features and targets of the dataset further:

print(iris.target)
"""
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2
 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
 2 2]
"""

Iris Flowers

In the context of the Iris dataset, the target comprises the species of each of the Iris flowers in the dataset with numerical encodings: 0 for Iris setosa, 1 for Iris versicolor, and 2 for Iris virginica. These numerical labels assist in the classification of species during analysis.

print(iris.feature_names)
"""
['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
"""

Conversely, feature_names provide the names of each feature of an Iris flower, which include sepal length, sepal width, petal length, and petal width.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal