#Guide PackageImportNumPy as NP#Read the iris DataSet data from the Sklearn packet's own data set fromSklearn.datasetsImportLoad_irisdata=Load_iris ()#View the data type, what is includedPrint("Data type:", type (data))Print("Data Category:", Data.keys ())#Remove the iris feature and Iris category data to see its shape and data typeIris_feature =Data.feature_names,data.dataPrint("Iris Features:", Iris_feature)Print("iris_feature Data Types", type (iris_feature)) Iris_target=Data.targetPrint("Iris Data Category:", Iris_target)Print("iris_target data type:", type (iris_target))#extract all the flowers of the calyx length (cm) of the dataSepal_len = Np.array (List (len[0) forLeninchdata.data))Print("calyx Length:", Sepal_len)#Remove all flower petal length (cm) + petal width (cm) dataPental_len = Np.array (List (len[2) forLeninchdata.data)) Pental_len.resize (3,50)#reallocate petal length memoryPental_wid = Np.array (List (len[3) forLeninchdata.data)) Pental_wid.resize (3,50)#Reallocate Petal width memoryIris_lens =(Pental_len,pental_wid)Print("Petal Length Width:", Iris_lens)#four characteristics of a flower and its categoryPrint("Features:", data.data[1])Print("Category:", data.target[1])#The characteristics and categories of all flowers are divided into three groups, each group of 50#set up 3 corresponding lists to hold dataIris_set =[]iris_ver=[]iris_vir= [] forIinchRange (0,150): ifData.target[i] = =0:data=data.data[i].tolist () data.append ('Setosa') iris_set.append (Data)elifData.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)#generate a new array with four features + categories per elementDatas =(iris_set,iris_ver,iris_vir)Print("the new array:", datas)
NumPy DataSet Exercise-Iris data set