写在前面
在写这篇文章之前,首先安利下jupyter,简直是神作,既可以用来写文章,又可以用来写代码,文章和代码并存,简直就是写代码/文章/教程的利器。
安装很简单:pip install jupyter 使用很简单: 当前面目录下shift+右键呼出在此处打开命令窗口,输入jupyter notebook召唤神龙。
上面这段文字在jupyter中是这样的(markdown格式):
本文介绍
基于iris数据集进行数据分析。 iris数据集是常用的分类实验数据集,由Fisher,1936收集整理。iris也称鸢尾花卉数据集,是一类多重变量分析的数据集。数据集包含150个数据样本,分为3类,每类50个数据,每个数据包含4个属性。可通过花萼长度,花萼宽度,花瓣长度,花瓣宽度4个属性预测鸢尾花卉属于(Setosa,Versicolour,Virginica)三个种类中的哪一类。(来自百度百科)
数据预处理
首先使用padas相关的库进行数据读取,处理和预分析。
pandas的可视化user guide参见:
https://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html
首先读取信息,并查看数据的基本信息:可以看到数据的字段,数量,数据类型和大小。%matplotlib notebookimport pandas as pdimport matplotlib.pyplot as plt# 读取数据iris = pd.read_csv('iris.data.csv') RangeIndex: 150 entries, 0 to 149 Data columns (total 5 columns): Sepal.Length 150 non-null float64 Sepal.Width 150 non-null float64 Petal.Length 150 non-null float64 Petal.Width 150 non-null float64 type 150 non-null object dtypes: float64(4), object(1) memory usage: 5.9+ KB# 前5个数据iris.head()
Sepal.LengthSepal.WidthPetal.LengthPetal.Widthtype05.13.51.40.2Iris-setosa
14.93.01.40.2Iris-setosa
24.73.21.30.2Iris-setosa
34.63.11.50.2Iris-setosa
45.03.61.40.2Iris-setosa# 数据描述iris.describe()
Sepal.LengthS