回顾练习
'''本次练习使用 鸢尾属植物数据集 .\iris.data ,在这个数据集中,包括了三类不同的鸢尾属植物:
Iris Setosa,Iris Versicolour,Iris Virginica。每类收集了50个样本,因此这个数据集一共包含了
150个样本。
sepallength:萼片长度
sepalwidth:萼片宽度
petallength:花瓣长度
petalwidth:花瓣宽度
'''
import numpy as np
outfile = r'E:\Python 学习代码\Dataset01\iris.data'
iris_data = np.loadtxt(outfile, dtype=object, delimiter=',', skiprows=0)
print(iris_data[0:10])
[['5.1' '3.5' '1.4' '0.2' 'Iris-setosa']
['4.9' '3.0' '1.4' '0.2' 'Iris-setosa']
['4.7' '3.2' '1.3' '0.2' 'Iris-setosa']
['4.6' '3.1' '1.5' '0.2' 'Iris-setosa']
['5.0' '3.6' '1.4' '0.2' 'Iris-setosa']
['5.4' '3.9' '1.7' '0.4' 'Iris-setosa']
['4.6' '3.4' '1.4' '0.3' 'Iris-setosa']
['5.0' '3.4' '1.5' '0.2' 'Iris-setosa']
['4.4' '2.9' '1.4' '0.2' 'Iris-setosa']
['4.9' '3.1' '1.5' '0.1' 'Iris-setosa']]
'''
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris # 导入数据集
iris = load_iris() # 载入数据
X= iris.data
y = iris.target
iris_data=np.column_stack((X,y))#将2个矩阵按列合并
outfile = r'.\iris.data'
pd.DataFrame(iris_data).to_csv(outfile)
iris_data = np.loadtxt(outfile, dtype=object, delimiter=',', skiprows= 1)
print(iris_data[:, 1:][0:10])
'''
print(sepalLength[0:10])
print(np.mean(sepalLength