KNN Python
Iris数据集概况
Iris Data Set(鸢尾属植物数据集)是我现在接触到的历史最悠久的数据集,它首次出现在著名的英国统计学家和生物学家Ronald Fisher 1936年的论文《The use of multiple measurements in taxonomic problems》中,被用来介绍线性判别式分析。在这个数据集中,包括了三类不同的鸢尾属植物:Iris Setosa,Iris Versicolour,Iris Virginica。每类收集了50个样本,因此这个数据集一共包含了150个样本。
特征
该数据集测量了所有150个样本的4个特征,分别是:
sepal length(花萼长度) features[0]sepal width(花萼宽度) features[1]petal length(花瓣长度) features[2]petal width(花瓣宽度) features[3]以上四个特征的单位都是厘米(cm)。
通常使用mm表示样本量的大小,nn表示每个样本所具有的特征数。因此在该数据集中,m=150,n=4
数据集的获取
该数据集被广泛用于分类算法的示例中,很多机器学习相关的数据都对这个数据集进行了介绍,因此可以获得的途径应该也会很多。
下面是该数据集存放的原始位置,该位置好像已经无法下载了,但是收集了使用该数据集的论文列表可供参考:
https://archive.ics.uci.edu/ml/datasets/Iris/
另一个比较方便的获取方式是,直接利用Python中的机器学习包scikit-learn直接导入该数据集,可参考Iris Plants Database,下面是具体的操作:
from sklearn.datasets import load_iris
data = load_iris()
print(dir(data))
print(data.DESCR)
import pandas as pd
pd.DataFrame(data=data.data, columns=data.feature_names)
下面是第3行和第4行的输出:
['DESCR', 'data', 'feature_names', 'target', 'target_names']
Iris Plants Database
====================
Notes
-----
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
This is a copy of UCI ML iris datasets.
http://archive.ics.uci.edu/ml/datasets/Iris
The famous Iris database, first used by Sir R.A Fisher
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.
References
----------
...
数据的可视化展示
将数据用图像的形式展示出来,可以对该数据集有一个直观的整体印象。下面利用该数据集4个特征中的后两个,即花瓣的长度和宽度,来展示所有的样本点。
import matplotlib.pyplot as plt
plt.style.use('ggplot')
X = data.data
y = data.target
features = data.feature_names
targets = data.target_names
plt.figure(figsize=(10, 4))
plt.plot(X[:, 2][y==0], X[:, 3][y==0], 'bs', label=targets[0])
plt.plot(X[:, 2][y==1], X[:, 3][y==1], 'kx', label=targets[1])
plt.plot(X[:, 2][y==2], X[:, 3][y==2], 'ro', label=targets[2])
plt.xlabel(features[2])
plt.ylabel(features[3])
plt.title('Iris Data Set')
plt.legend()
plt.savefig('Iris Data Set.png', dpi=200)
plt.show()
利用上面的代码画出来的图如下:
Reference
https://en.wikipedia.org/wiki/Iris_flower_data_set
https://archive.ics.uci.edu/ml/datasets/Iris/
https://matplotlib.org/users/style_sheets.html
http://scikit-learn.org/stable/datasets/index.html#iris-plants-database
---------本文转自https://www.cnblogs.com/Belter/p/8831216.html
相关知识
用python实现KNN算法对鸢尾花的分类
Python实现kNN算法,使用鸢尾花作为测试数据
KNN鸢尾花分类
Python原生代码实现KNN算法(鸢尾花数据集)
knn
Python实现KNN算法(鸢尾花数据)
【python机器学习】KNN算法实现回归(基于鸢尾花数据集)
鸢尾花数据分类,通过Python实现KNN分类算法。
KNN分类算法介绍,用KNN分类鸢尾花数据集(iris)
KNN算法实现鸢尾花数据集分类
网址: KNN Python https://www.huajiangbk.com/newsview1842686.html
上一篇: 微囊藻属的危害 |
下一篇: 鸢尾属鸢尾花传说 |
推荐分享

- 1君子兰什么品种最名贵 十大名 4012
- 2世界上最名贵的10种兰花图片 3364
- 3花圈挽联怎么写? 3286
- 4迷信说家里不能放假花 家里摆 1878
- 5香山红叶什么时候红 1493
- 6花的意思,花的解释,花的拼音 1210
- 7教师节送什么花最合适 1167
- 8勿忘我花图片 1103
- 9橄榄枝的象征意义 1093
- 10洛阳的市花 1039