當我們有一個新的機器學習演算法時,為展現其效果以及與其他演算法的差異,我們可以使用共通的資料集(Dataset)來進行測試與比較,才有一個共同的標準。本篇將簡單介紹 Iris dataset 內容與結構,之後也會持續介紹許多常用的 Dataset 相關內容。

Iris dataset 是一個古典的花朵資料集,由英國統計學家 Ronald Fisher 爵士在1936年時,對加斯帕半島上的鳶尾屬花朵所提取的花瓣花萼的長寬數據資料,依照山鳶尾,變色鳶尾,維吉尼亞鳶尾三類進行標示,共150筆資料。

Attributes and Labels

Iris dataset 中包含四種屬性 (Atrributes) 與三種花卉標籤 (Labels)

Attributes

  • Sepal length: 花萼長度 (cm)
  • Sepal width: 花萼寬度 (cm)
  • Petal length: 花瓣長度 (cm)
  • Petal width: 花瓣寬度 (cm)

Labels

  • setosa: 山鳶尾
  • versicolor: 變色鳶尾
  • virginica: 維吉尼亞鳶尾

表格顯示如下

Sepal Length Sepal Width Petal Length Petal Width Label
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
7.0 3.2 4.7 1.4 versicolor
6.4 3.2 4.5 1.5 versicolor
6.3 3.3 6.0 2.5 virginica
5.8 2.7 5.1 1.9 virginica

How to use

因 Iris dataset 已經常被拿來使用作為資料科學的範例,因此有許多 Machine Learning 套件已經包含該資料集,或有需求時可直接下載到 Local 端加以使用。我們以 Python 機器學習資料集 Scikit-learn 為例,

from sklearn import datasets
iris = datasets.load_iris()

即可讀入 Iris dataset,而輸入 print(iris.DESCR) 可顯示該資料集詳細描述

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 資料在 iris.data,而 Label 在 iris.target

print(iris.data[:2])

# show [[5.1 3.5 1.4 0.2], [4.9 3.0 1.4 0.2]]

print(iris.target[:2])

# show [0, 0]

代表第一筆資料 [5.1, 3.5, 1.4, 0.2] 與第二筆資料 [4.9 3.0 1.4 0.2] 對應到的 Label 為 0。而每個 feature 與 label 對應到的特徵內容可使用 feature_namestarget_names 來顯示

print(iris.feature_names)

# ['sepal length (cm)',
#  'sepal width (cm)',
#  'petal length (cm)',
#  'petal width (cm)']

print(iris.target_names)

# ['setosa', 'versicolor', 'virginica']

feature 顯示代表 iris.data[0][0] = 5.1sepal lenght,而 iris.data[0][1] = 3.5 代表 sepal width 等。而 Label 0 代表 setosa

了解該資料集的結構後,我們就可以對該資料進行一些簡單的應用,如 K-mean 分群 (Clustering) 等,方法可參考 Scikit-learn 上的範例

Reference