Desicionttreeclassifier () Invocation of decision tree algorithm in Sklearn and application of Sklearn packet Sklearn.datasets.load_iris ()

Source: Internet
Author: User

A simple call to the decision tree method records

1clf=Tree. Decisiontreeclassifier ()2datamat=[];labelmat=[]3Datapath='d:/machinelearning data/machinelearninginaction/ch05/testset.txt'4FR =Open (DataPath)5  forLineinchFr.readlines ():#readilnes () The contents of the file exist in the list6Linearr = Line.strip (). Split ()#Remove Spaces7Labelmat.append (int (linearr[-1]))8Datamat.append ([Float (linearr[0]), float (linearr[1])])  9x=Np.array (Datamat)Teny=Np.array (Labelmat) One clf.fit (x, y) Ayhat=clf.predict (x) -Result=np.count_nonzero (yhat==y) - Print('correct number', result) the Print('correct rate', Result/len (Yhat))
View Code

Links to the decision tree are attached http://scikit-learn.org/stable/modules/tree.html

Sklearn of the data in the application Sklearn.datasets.load_iris () call and the corresponding application link: http://scikit-learn.org/stable/modules/generated/ Sklearn.datasets.load_iris.html#sklearn.datasets.load_iris

Desicionttreeclassifier () Invocation of decision tree algorithm in Sklearn and application of Sklearn packet Sklearn.datasets.load_iris ()

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.