How can I perform a cross validation with a multinomial logit model?

I want to create a code similar to this one, where I used a Discriminant Analysis model, but I can't use the function predict
X = transpose(FEAT4);
Y = categorical(Lab);
% In this example, we will hold 40% of the data, selected randomly, for
% test phase.
cv = cvpartition(length(FEAT4),'holdout',0.40);
% Training set
Xtrain = X(training(cv),:);
Ytrain = Y(training(cv),:);
% Test set
Xtest = X(test(cv),:);
Ytest = Y(test(cv),:);
disp('Training Set')
tabulate(Ytrain)
disp('Test Set')
tabulate(Ytest)
% Make a prediction for the test set
da = ClassificationDiscriminant.fit(Xtrain,Ytrain);
% Make a prediction for the test set
Y_da = da.predict(Xtest);
% Compute the confusion matrix
C_da = confusionmat(Ytest,Y_da);
% Examine the confusion matrix for each class as a percentage of the true class
C_da = bsxfun(@rdivide,C_da,sum(C_da,2)) * 100
Can I do this? Is there another way to obtain the same results? Otherwise, how can I recreate the function "predict"?

Answers (0)

Asked:

on 7 Nov 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!