K-Fold cross-validation (K-fold crossvalidation)

Source: Internet
Author: User
K-Fold cross-validation (K-fold crossvalidation):
In machine learning, data set A is divided into training set (training set) B and test set C, in case of insufficient sample size, in order to make full use of the data set to test the algorithm effect, dataset A is randomly divided into k packets, each time one of the packages as a test set, The rest of the K-1 package is trained as a training set.
In Matlab, you can take advantage of:
Indices=crossvalind (' Kfold ', x,k);
To implement the operation of the random subcontracting, where X is an n willi Vector (n is the number of elements of the dataset A, independent of the X content, only need to be able to represent the size of the dataset), K is the total number of packets to be divided, the result of the output indices is an n willi Vector, The value corresponding to each element is the number of the package to which the cell belongs (that is, the element in the column vector is the integer random number of the 1~k), which is used to divide the dataset using the loop control. Cases:
[M,n]=size (data);//The DataSet is a m*n matrix, where each row represents a sample
Indices=crossvalind (' Kfold ', data (1:m,n), 10);//Random subcontracting
For k=1:10//cross-validation k=10,10 package turns as a test set
Test = (Indices = = k); Get the unit number that the test set element corresponds to in the data set
Train = number of the ~test;//train set element is not a test element
Train_data=data (train,:);//partition data from a train sample from a data set
Train_target=target (:, train);//Get the test target of the sample set, in this case the actual classification
Test_data=data (test,:);//test Sample Set
Test_target=target (:, test);
[Hammingloss (1,k), Rankingloss (1,k), Oneerror (1,k), Coverage (1,k), Average_precision (1,k), OUTPUTS,PRE_LABELS.MLKNN ]=mlknn_algorithm (train_data,train_target,test_data,test_target);//The algorithm to be validated
The above results are several verification indexes of the output algorithm MLKNN and the final verification output and result matrix, each of which is a K element row vector

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.