数据集:鸢尾花卉

数据集:鸢尾花卉

进阶分析: k k k近邻法】

数据集介绍

数据集来源 UCI 数据库 Iris
概述 UCI Iris 数据集原始数据,根据鸢花萼片和花瓣4项指标对花的种类进行分类。
数据介绍 UCI Iris是常用分类建模数据集,通过花萼长度,花萼宽度,花瓣长度,花瓣宽度4个属性预测鸢尾花卉属于(Setosa,Versicolour,Virginica)三个种类中的哪一类。
属性数 5
记录数 150
无缺失值记录数 150

数据集元数据

名称 数据类型
萼片宽度 float
萼片长度 float
花瓣长度 float
花瓣宽度 float
鸢花种类 string

专有名词

中文 英文
萼片 C a l y x Calyx Calyx
花瓣 P e t a l Petal Petal
长度 L e n g t h Length Length
宽度 W i d t h Width Width
鸢花 I r i s Iris Iris

预处理

# 导包
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# 读取文件
fname = 'iris.data'
with open(fname,'r+',encoding='utf-8') as f:
    s = [i[:-1].split(',') for i in f.readlines()]

# pandas读取数据,样本数各50个
names = ['slength','swidth','plength','pwidth','name']
iris = pd.DataFrame(data=s,columns=names)
iris

数据预览

索引 slength swidth plength pwidth name
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
146 6.3 2.5 5.0 1.9 Iris-virginica
147 6.5 3.0 5.2 2.0 Iris-virginica
148 6.2 3.4 5.4 2.3 Iris-virginica
149 5.9 3.0 5.1 1.8 Iris-virginica
150 None None None None None
151 rows × 5 columns

分组统计

# 三种类别
Setosa = iris.iloc[0:50,0:4].astype('float')
Versicolour = iris.iloc[50:100,0:4].astype('float')
Virginica = iris.iloc[100:150,0:4].astype('float')

# 统计每个品种有多少个样本
iris['name'].value_counts()

整体样本数

Iris-versicolor    50
Iris-virginica     50
Iris-setosa        50
Name: name, dtype: int64

统计每个类别每个数据点出现的个数

# setosa
Setosa.loc[:,'slength'].value_counts(),Setosa.loc[:,'swidth'].value_counts(),Setosa.loc[:,'plength'].value_counts(),Setosa.loc[:,'pwidth'].value_counts()
# versicolour
Versicolour.loc[:,'slength'].value_counts(),Versicolour.loc[:,'swidth'].value_counts(),Versicolour.loc[:,'plength'].value_counts(),Versicolour.loc[:,'pwidth'].value_counts()
# virginica
Virginica.loc[:,'slength'].value_counts(),Virginica.loc[:,'swidth'].value_counts(),Virginica.loc[:,'plength'].value_counts(),Virginica.loc[:,'pwidth'].value_counts()

分组样本数

# Setosa:
(5.0    8
 5.1    8
 4.8    5
 5.4    5
 4.9    4
 4.6    4
 5.2    3
 4.4    3
 4.7    2
 5.7    2
 5.5    2
 4.5    1
 5.8    1
 4.3    1
 5.3    1
 Name: slength, dtype: int64,
 3.4    9
 3.5    6
 3.0    6
 3.1    5
 3.2    5
 3.8    4
 3.7    3
 3.9    2
 3.3    2
 3.6    2
 2.9    1
 4.1    1
 4.4    1
 4.2    1
 2.3    1
 4.0    1
 Name: swidth, dtype: int64,
 1.5    14
 1.4    12
 1.6     7
 1.3     7
 1.7     4
 1.9     2
 1.2     2
 1.1     1
 1.0     1
 Name: plength, dtype: int64,
 0.2    28
 0.4     7
 0.3     7
 0.1     6
 0.5     1
 0.6     1
 Name: pwidth, dtype: int64)

# Versicolour:
(5.6    5
 5.7    5
 5.5    5
 6.0    4
 6.1    4
 6.3    3
 6.7    3
 5.8    3
 6.2    2
 5.0    2
 6.4    2
 6.6    2
 5.9    2
 5.2    1
 5.4    1
 5.1    
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DeeGLMath

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值