Python's Sklearn cross-validation data splitting

Source: Internet
Author: User

The K-fold verification proposed in this paper is the Stratifiedkfold method in the Sklearn package in Python.

The idea of the method is described: http://scikit-learn.org/stable/modules/cross_validation.html

Stratifiedkfold Is a variation of K-fold which returns stratified Folds:each set contains approximately the same percentage of samples of each target class as the complete set.

Translation

Stratifiedkfold is the one that sets each sample in the data set Data composition, split by equal means.

Other Partitioning methods See:http://scikit-learn.org/stable/modules/cross_validation.html

Gossip less, directly on the code.

"Stud Wire Source"

Import numpyimport h5pyimport sklearnfrom sklearn import cluster,cross_validationfrom sklearn.cluster Import Agglomerativeclusteringfrom sklearn.cross_validation Import stratifiedkfold## generates a random matrix and saves #arr = Numpy.random.random ( [200,400]) #labvec = [] #for i in Numpy.arange (0,200): #    j = i%10#    arr[i,j*20:j*20+20] = arr[i,j*20:j*20+20]+10#    Labvec.append (j) #arr = arr. T#file = h5py. File (' Arr.mat ', ' W ')    #file. Create_dataset (' arr ', data = arr) #file. Close () #file = h5py. File (' Labvec.mat ', ' W ')    #file. Create_dataset (' Labvec ', data = Labvec) #file. Close () # Read to open files Myfile=h5py. File (' Arr.mat ', ' r ') arr = myfile[' arr '][:]myfile.close () arr = arr. Tmyfile=h5py. File (' Labvec.mat ', ' r ') Labvec = myfile[' Labvec '][:]myfile.close () SKF = Stratifiedkfold (Labvec, 4) Train_set = []test_ set = []for train, Test in SKF:    train_set.append (train)    test_set.append (test)


See: http://scikit-learn.org/stable/modules/cross_validation.html

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Python's Sklearn cross-validation data splitting

Related Article

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.