iris数据集的可视化

import numpy as np
from sklearn.datasets import load_iris
from matplotlib import pyplot as plt

data = load_iris()
features = data['data']
feature_names = data['feature_names']
target = data['target']


pairs = [(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)]
#数据每50种一类,target中一共有三种,对第一种,取features中的前五十行,t的范围range(3)(0.1.2)
#marker标记“>ox”分别为三角圈叉,c颜色。
#索引,features[target==0,0]为前五十行第一列的数据
for i,(p0,p1) in enumerate(pairs):
    plt.subplot(2,3,i+1)#enumerate返回的索引值i是从0开始的。subplot(2,3,1)表示两行三列的第一个图

    for t,marker,c in zip(range(3),">ox","rgb"):
        plt.scatter(features[target == t,p0], features[target == t,p1], marker=marker, c=c)
    plt.xlabel(feature_names[p0])
    plt.ylabel(feature_names[p1])
    plt.xticks([])
    plt.yticks([])
plt.savefig (r'C:\Users\Administrator\Pictures\one.jpg')
#提取所有的花瓣长度数据,150个
plength=features[:,2]

#提取 setosa 和 非setosa 的花瓣长度,我把原文稍微修改了一下,比较好理解
#需要了解target与features的对应关系。
is_setosa=(target==0)
setosa_plength=plength[is_setosa]
other_plength=plength[~is_setosa]

#找出 setosa 花瓣的最大长度,和 非setosa花瓣的最小长度
max_setosa=setosa_plength.max()
min_non_setosa=other_plength.min()

#根据下面输出的数据可知 setosa 花瓣的最大长度,和 非setosa花瓣的最小长度没有重合
#因此如果一朵花的花瓣长度小于2的话,那么是setosa的可能性就非常大。
print('Maximun of setosa: {0}.'.format(max_setosa)) #输出值是1.9
print('Minimum of others: {0}.'.format(min_non_setosa)) #输出值是3.
#这里就是给出区别setasa和其他花的模型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值