NumPy Data Set Exercises

Source: Internet
Author: User

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

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.