numpy数据集
#1.安裝scipy,numpy,sklearn包
import numpy
from sklearn.datasets import load_iris
#2.從sklearn包自帶的數(shù)據(jù)集中讀出鳶尾花數(shù)據(jù)集data
#3.查看data類型,包含哪些數(shù)據(jù)
data = load_iris()
type(data)
print(data.keys()) ?
3.運(yùn)行結(jié)果:
#4.取出鳶尾花特征和鳶尾花類別數(shù)據(jù),查看其形狀及數(shù)據(jù)類型 #特征 iris_feature = data['data'] print(iris_feature)#類別數(shù)據(jù) iris_target = data.target,data.target_names print('形狀類型:',iris_target)4. 運(yùn)行結(jié)果:
# 5.取出所有花的花萼長度(cm)的數(shù)據(jù)iris_length=numpy.array(list(len[0] for len in data['data'])) print(iris_length)5. 運(yùn)行結(jié)果:
?
# 6.取出所有花的花瓣長度(cm)+花瓣寬度(cm)的數(shù)據(jù) # 長度 iris_length=numpy.array(list(len[2] for len in data['data'])) print(iris_length) #寬度 iris_width=numpy.array(list(len[3] for len in data['data'])) print(iris_width)6. 運(yùn)行結(jié)果:
?
# 7.取出某朵花的四個特征及其類別。print(data['data'][0],data['target_names'][0])7. 運(yùn)行結(jié)果:
# 8.將所有花分成三個組,每組50個iris_setosa=[] iris_versicolor=[] iris_virginica=[]for i in range(0,150): if data['target'][i]==0:data1=data['data'][i].tolist()data1.append('setosa')iris_setosa.append(data1)elif data['target'][i]==1:data1=data['data'][i].tolist()data1.append('versicolor')iris_versicolor.append(data1)else:data1=data['data'][i].tolist()data1.append('virginica')iris_virginica.append(data1)# 9.形成新的數(shù)組來存放三個類別的花朵datas=np.array([iris_setosa,iris_versicolor,iris_virginica]) print(datas) ?
8.運(yùn)行結(jié)果:
?
轉(zhuǎn)載于:https://www.cnblogs.com/844115-l/p/9786638.html
總結(jié)
- 上一篇: c++中运算符重载
- 下一篇: 防止API被恶意调用,一般有哪些方法?