NumPy DataSet Exercise-Iris data set

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.