I cannot follow crossval() & cvpartition() function given in MATLAB documentation crossval(). What goes in the parameter and how would it help to compare performance and accuracy of different classifiers. Would be obliged if a simpler version of it is provided here.
I cannot follow crossval() & cvpartition() function given in MATLAB documentation crossval() . What
Share
Let’s work on Example 2 from CROSSVAL documentation.
Here we loaded the data from example mat-file and assigned variable to
Xandy.measamtrix contains different measurements of iris flowers andspeciesare tree classes of iris, what we are trying to predict with the data.Cross-validation is used to train a classifier on the same data set many times. Basically at each iteration you split the data set to training and test data. The proportion is determined by k-fold. For example, if
kis 10, 90% of the data will be used for training, and the rest 10% – for test, and you will have 10 iterations. This is done by CVPARTITION function.You can explore
cpobject if you typecp.and press Tab. You will see different properties and methods. For example,find(cp.test(1))will show indices of the test set for 1st iteration.Next step is to prepare prediction function. This is probably where you had the main problem. This statement create function handle using anonymous function.
@(XTRAIN, ytrain,XTEST)part declare that this function has 3 input arguments. Next part(classify(XTEST,XTRAIN,ytrain))defines the function, which gets training dataXTRAINwith knownytrainclasses and predicts classes forXTESTdata with generated model. (Those data are fromcp, remember?)Then we are running CROSSVAL function to estimate missclassification rate (mcr) passing the complete data set, prediction function handle and partitioning object
cp.Still have questions?