Issues related to graphics in pattern recognition (part 1)

I can not run crossval()

and cvpartition()

function specified in the documentation for the MATLAB crossval () . What is included in the parameter and how it will help you compare the performance and accuracy of different classifiers. Would be a must if a simpler version is presented here.

+3


source to share


1 answer


Let's work on example 2 from the CROSSVAL documentation.

load('fisheriris');
y = species;
X = meas;

      

Here we have loaded the data from the example mat file and assigned the variable to X

and y

. meas

amtrix contains various dimensions of iris colors and species

are the iris tree classes that we are trying to predict with the data.

Cross validation is used to train a classifier on the same dataset many times. Basically, in each iteration, you split the dataset into training and test data. The share is determined by k-fold. For example, if it k

is 10, 90% of the data will be used for training and the remaining 10% for the test, and you will have 10 iterations. This is done using the CVPARTITION function .

cp = cvpartition(y,'k',10); % Stratified cross-validation

      

You can explore the object cp

if you type cp.

and press Tab. You will see various properties and methods. For example, it find(cp.test(1))

will show the test case indices for the 1st iteration.



The next step is to prepare the forecasting function. This was probably the main problem. This operator creates a function handle using an anonymous function. The part @(XTRAIN, ytrain,XTEST)

states that this function has 3 input arguments. The next part (classify(XTEST,XTRAIN,ytrain))

defines a function that gets training data XTRAIN

with known ytrain

classes and predicts classes for the data XTEST

with a generated model. (This data is from cp

, remember?)

classf = @(XTRAIN, ytrain,XTEST)(classify(XTEST,XTRAIN,ytrain));

      

We then run the CROSSVAL function to estimate the throughput rate (mcr) passing the complete dataset, the handle to the predictor function, and the split object cp

.

cvMCR = crossval('mcr',X,y,'predfun',classf,'partition',cp)
cvMCR =
    0.0200

      

You have questions?

+2


source







All Articles