Python 鸢尾花的可视化

通过读取sklearn自带鸢尾花数据包,实现数据可视化:

代码:

from sklearn import datasets

import pandas as pd

iris_datas = datasets.load_iris()

print(iris_datas.data)

from collections import Counter, defaultdict

import matplotlib

import matplotlib.pyplot as plt

import numpy as np

matplotlib.rcParams['font.sans-serif'] = ['SimHei']

style_list = ['o', '^', 's']

data = iris_datas.data

labels = iris_datas.target_names

cc = defaultdict(list)

for i, d in enumerate(data):

    cc[labels[int(i/50)]].append(d)

p_list = []

c_list = []

for each in [0, 2]:

    for i, (c, ds) in enumerate(cc.items()):

        draw_data = np.array(ds)

        p = plt.plot(draw_data[:, each], draw_data[:, each+1], style_list[i])

        p_list.append(p)

        c_list.append(c)

plt.legend(map(lambda x: x[0], p_list), c_list)

plt.title('鸢尾花花瓣的长度和宽度') if each else plt.title('鸢尾花花萼的长度和宽度')

plt.xlabel('花瓣的长度(cm)') if each else plt.xlabel('花萼的长度(cm)')

plt.ylabel('花瓣的宽度(cm)') if each else plt.ylabel('花萼的宽度(cm)')

plt.subplots_adjust(wspace=1)

plt.show()

散点图:

Python 鸢尾花的可视化_第1张图片

 

你可能感兴趣的:(数据挖掘,python)