1. 鳶尾花Iris數據集介紹
Iris flower數據集是1936年由Sir Ronald Fisher引入的經典多維數據集,可以作爲判別分析(discriminant analysis)的樣本。
該數據集包含Iris花的三個品種(Iris setosa, Iris virginica and Iris versicolor)各50個樣本,
,Fisher利用這個數據集開發了一個線性判別模型來辨別花朵的品種。
每個樣本還有4個特徵參數(分別是萼片的長寬和花瓣的長寬,以釐米爲單位)
sepal length (cm), sepal width (cm), petal length (cm), petal width (cm)
基於Fisher的線性判別模型,該數據集成爲了機器學習中各種分類技術的典型實驗案例
2. Sklearn代碼獲取Iris
from sklearn import datasets
iris = datasets.load_iris()
irisFeatures = iris["data"]
irisFeaturesName = iris["feature_names"]
irisLabels = iris["target"]
print('Iris feature name:',irisFeaturesName)
print('Iris data size :',irisFeatures.shape)
print(irisFeatures[:10])
print('Iris label size :', irisLabels.shape)
print(irisLabels[:10])
Iris feature name: ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
Iris data size : (150, 4)
[[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]]
Iris label size : (150,)
[0 0 0 0 0 0 0 0 0 0]
2. 描述性統計
import pandas as pd
print(irisFeaturesName)
dataset = pd.DataFrame(irisFeatures, columns=['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'])
print(dataset.describe())
(sepal length)花萼長度最小值4.30, 最大值7.90, 均值5.84, 中位數5.80, 右偏
(sepal width)花萼寬度最小值2.00, 最大值4.40, 均值3.05, 中位數3.00, 右偏
(petal length)花瓣長度最小值1.00, 最大值6.90, 均值3.76, 中位數4.35, 左偏
(petal width)花瓣寬度最小值0.10, 最大值2.50, 均值1.20, 中位數1.30, 左偏
按中位數來度量: 花萼長度 > 花瓣長度 > 花萼寬度 > 花瓣寬度
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
count 150.000000 150.000000 150.000000 150.000000
mean 5.843333 3.057333 3.758000 1.199333
std 0.828066 0.435866 1.765298 0.762238
min 4.300000 2.000000 1.000000 0.100000
25% 5.100000 2.800000 1.600000 0.300000
50% 5.800000 3.000000 4.350000 1.300000
75% 6.400000 3.300000 5.100000 1.800000
max 7.900000 4.400000 6.900000 2.500000
3. 箱線圖
boxplot所繪製的就是箱線圖, 它能顯示出一組數據的最大值, 最小值, 四分位數以及異常點.
對於異常點的定義: 區間[Q1-1.5IQR, Q3+1.5IQR]之外的點, 其中Q1下四分位數(25%), Q3上四分位數(75%), IQR=Q3-Q1
url = r"C:\Users\harry\PycharmProjects\helloworld\ML\DataSets_test\data\iris.csv"
names = ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)', 'class']
dataset = pd.read_csv(url, names=names)
print(dataset.describe())
dataset.plot.box()
plt.show()
4. 數據分佈情況
import matplotlib.pyplot as plt
s = dataset.hist() # 數據直方圖histograms
print(s)
plt.show()