ImportNumPy fromSklearn.datasetsImportLoad_iris#Read the iris DataSet data from the Sklearn packet's own data setData=Load_iris ()Print(data)Print(Type (data))#View Data TypesData.keys ()#what data is included#Remove the iris feature and Iris category data to see its shape and data typeiris_feature=data['Feature_names'],data['Data']iris_target=Data.target_names,data.targetPrint('Iris Data:', Iris_feature)Print('Iris shape Category:', Iris_target) Sepal_len= Numpy.array (List (len[0) forJeinchdata['Data']))Print('all calyx Lengths:', Sepal_len)#Remove all flower petal length (cm) + petal width (cm) dataPetal_len = Numpy.array (List (len[2) forLeninchdata['Data'])) Petal_len.resize (5,30)#re-allocating petal length Petal_len memoryPetal_wid = Numpy.array (List (len[3) forLeninchdata['Data'])) Petal_wid.resize (5,30)#Reallocate Petal width petal_wid memoryIris_lens =(Petal_len,petal_wid)Print('all petals long width:', Iris_lens)#take out the four characteristics of a flower and its category. Print(data['Data'][1],data['Target'][1])#The characteristics and categories of all flowers are divided into three groups, each group of 50Iris_set = []#0 indicates the iris of the mountainIris_ver = []#1 indicates the variegated irisIris_vir = []#3 indicates Virginia Iris . forIinchRange (0,150):#for loop traversal of all data ifdata['Target'][i] = = 0:#category 0 for Setosa, generates a Setosa class iris datadb = data['Data'][i].tolist () db.append ('Setosa') iris_set.append (db)elifdata['Target'][i]==1:#A category of 1 is versicolor, which generates a versicolor class iris datadb = data['Data'][i].tolist () db.append ('versicolor') iris_ver.append (db)Else:#the remaining categories are virginica Iris datadb = data['Data'][i].tolist () db.append ('virginica') iris_vir.append (db)#9. Generate a new array with four features + categories per elementIris_result =Numpy.array ([Iris_set, Iris_ver, Iris_vir])Print("Group:", Iris_result)
Results:
NumPy Data Set Exercises