鸢尾花(Iris)数据集
生活随笔
收集整理的這篇文章主要介紹了
鸢尾花(Iris)数据集
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
鳶尾花數(shù)據(jù)集
- 1. 鳶尾花數(shù)據(jù)集下載
- 2. Pandas庫基礎(chǔ)操作
- 3. 數(shù)據(jù)可視化
1. 鳶尾花數(shù)據(jù)集下載
- 下載鳶尾花數(shù)據(jù)集
| fname | 下載后的文件名 |
| origin | 文件的URL地址 |
| cache_dir | 下載后文件的存儲位置 |
iris_training.csv訓(xùn)練數(shù)據(jù)集,120條樣本數(shù)據(jù);iris_test.csv測試數(shù)據(jù)集,30條數(shù)據(jù)。本文只用到訓(xùn)練數(shù)據(jù)集,其中有花萼長度(Sepal Length)、花萼寬度(Sepal Width)、花瓣長度(Petal Length)、花瓣寬度(Petal Width)四個屬性。標(biāo)簽0、1、2分別表示山鳶尾(Setosa)、變色鳶尾(Versicolor)、維吉尼亞鳶尾(Virginical)。
- split()函數(shù)(知識擴(kuò)充):通過指定的分隔符對字符串進(jìn)行切片,并返回一個列表。
2. Pandas庫基礎(chǔ)操作
用于數(shù)據(jù)統(tǒng)計和分析、可以高效、方便地操作大型數(shù)據(jù)集。
- 導(dǎo)入Pandas庫
- 讀取csv數(shù)據(jù)集文件
輸出結(jié)果如下:
- head()函數(shù)
讀取前n行數(shù)據(jù),參數(shù)為空時,默認(rèn)讀取而是為數(shù)據(jù)表中的前5行數(shù)據(jù)。 - tail()函數(shù)
讀取后n行數(shù)據(jù),參數(shù)為空時,默認(rèn)讀取而是為數(shù)據(jù)表中的后5行數(shù)據(jù) - 索引和切片訪問數(shù)據(jù)
df_iris[n:m]表示讀取行號n到行號m-1的數(shù)據(jù)樣本 - describe()函數(shù)
顯示二維數(shù)據(jù)的統(tǒng)計信息,輸出總數(shù)、平均值、標(biāo)準(zhǔn)差、最小值等信息。
輸出結(jié)果如下:
- DataFrame的常用屬性
| nmid | 數(shù)據(jù)表的維數(shù) |
| shape | 數(shù)據(jù)表的形狀 |
| size | 數(shù)據(jù)表元素的總個數(shù) |
- 轉(zhuǎn)化為NumPy數(shù)組
轉(zhuǎn)化為NumPy數(shù)組后,可以利用索引和切片訪問數(shù)組元素,比如iris[0:6]表示讀取前6行數(shù)據(jù),iris[0:6,0:4]表示讀取前6行數(shù)據(jù)的前4列。
3. 數(shù)據(jù)可視化
循環(huán)輸出所有屬性關(guān)系圖
import tensorflow as tf import pandas as pd import numpy as np import matplotlib.pyplot as pltTRAIN_URL="http://download.tensorflow.org/data/iris_training.csv" train_path=tf.keras.utils.get_file(TRAIN_URL.split('/')[-1],TRAIN_URL)column_names=['SepalLength','SepalWidth','PetalLength','PetalWidth','Species'] df_iris=pd.read_csv(train_path,header=0,names=column_names)iris=np.array(df_iris)fig=plt.figure('Iris Data',figsize=(15,15))plt.suptitle("Andreson's Iris Dara Set\n(Blue->Setosa|Red->Versicolor|Green->Virginical)")for i in range(4):for j in range(4):plt.subplot(4,4,4*i+(j+1))if(i==j):plt.text(0.3,0.4,column_names[i],fontsize=15)else:plt.scatter(iris[:,j],iris[:,i],c=iris[:,4],cmap='brg')if(i==0):plt.title(column_names[j])if(j==0):plt.ylabel(column_names[i])plt.show()輸出結(jié)果如下:
總結(jié)
以上是生活随笔為你收集整理的鸢尾花(Iris)数据集的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “元宇宙” 是什么东西?
- 下一篇: 嵌入式系统开发者需要掌握什么技术?