Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.