iris数据集进行KNN分类

本文介绍了使用Iris数据集进行KNN分类的实验,详细阐述了数据集信息、来源以及KNN分类的基本原理。通过对比不同k值、是否进行数据标准化以及选择不同的标准化方法对分类结果的影响,揭示了k值的选择和数据预处理在模型性能中的关键作用。实验结果显示,未标准化数据、k=3时错误率较低,但数据标准化方法对结果有显著影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据集说明

Data Set Information:

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.

Predicted attribute: class of iris plant.

This is an exceedingly simple domain.

This data differs from the data presented in Fishers article (identified by Steve Chadwick, spchadwick ‘@’ espeedaz.net ). The 35th sample should be: 4.9,3.1,1.5,0.2,”Iris-setosa” where the error is in the fourth feature. The 38th sample: 4.9,3.6,1.4,0.1,”Iris-setosa” where the errors are in the second and third features.

Attribute Information:

  1. sepal length in cm
  2. sepal width in cm
  3. petal length in cm
  4. petal width in cm
  5. class:
    – Iris Setosa
    – Iris Versicolour
    – Iris Virginica

数据集来源

http://archive.ics.uci.edu/ml/
关于机器学习的数据很多的,可用来做练习

KNN分类说明

knn算法链接
1.随机的划分测试集和训练集
7:3 和6:4
2.数据是否标准化,以及选取标准化的方法
3.选取合适的k

测试结果

只对选取6:4的进行说明,训练集过多的话,预测效果比较好的
1.不标准化,k=3

>>> reload(iris)
<module 'iris' from 'iris.py'>
>>> iris.irisClassTest()
2.0 0.966666666667
>>> iris.irisClassTest()
1.0 0.983333333333
>>> iris.irisClassTest()
2.0 0.966666666667
>>> iris.irisClassTest()
2.0 0.966666666667
>>> iris.irisClassTest()
1.0 0.983333333333
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值