#安装scipy, Numpy,sklearn bagImportNumPy as np# reading the iris DataSet from the Sklearn packet's own data set Datafrom sklearn.datasetsImportLoad_irisdata=Load_iris () # Look at the data type, which print is included ("Data type:", type (data) print ("Data Category:", Data.keys ()) # Remove the iris feature and Iris category data to see its shape and data type Iris_feature=Data.feature_names,data.dataprint ("Iris Characteristics:", iris_feature) print ("Iris_feature Data Type", type (iris_feature)) Iris_target=Data.targetprint ("Iris Data Category:", Iris_target) print ("Iris_target Data type:", type (iris_target)) # Remove All the flowers of the calyx length (cm) of the data Sepal_len= Np.array (List (len[0) forlen in Data.data)) Print ("Calyx Length:", Sepal_len) # Remove all flower petals length (cm)+petal Width (cm) data Pental_len= Np.array (List (len[2) forlen in Data.data)) Pental_len.resize (2,50) #重新分配花瓣长度内存pental_wid= Np.array (List (len[3) forlen in Data.data)) Pental_wid.resize (2,50) #重新分配花瓣宽度内存iris_lens=(pental_len,pental_wid) print ("Petal Length width:", Iris_lens) # Take out four features of a flower and its category print ("Features:", data.data[1]) print ("Category:", data.target[1] # divides the characteristics and categories of all flowers into three groups, each set of 50 # establishes 3 corresponding lists to hold the data iris_set=[]iris_ver=[]iris_vir= [] forI in range (0,150): ifData.target[i] = = 0: Data=data.data[i].tolist () data.append (' Setosa ') iris_set.append (Data) elif Data.target[i]==1: Data=data.data[i].tolist () data.append (' Versicolor ') iris_ver.append (Data)Else: Data=data.data[i].tolist () data.append (' Virginica ') Iris_vir.append (Data) # generates a new array with four features per element+category Datas=(iris_set,iris_ver,iris_vir) print ("New array:", datas)
NumPy Data Set