How to make matrix a possitive definite

S
Saishasingh · Jul 20, 2020 · 1.9K views
Question
Hi Everyone, I have a problem with classification. I have 39 samples of training data (39x10935) and 347 samples of testing data (347x10935). classify function returns: "The covariance matrix of each group in TRAINING must be positive definite" error. Is there any method to compute the minimal size of training set? I know that I could just add some test samples to the training set, but the nature of the problem that I am solving requires as little training samples as possible.
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 27, 2026
I understand that you may need as few training samples as possible. However, this is not always good, since your performance will not be so good (obviously).
If you really need to do so, I recommend you to use MATLAB's CVPARTITION. Choose 'holdout' method and try with different proportions until you find the minimum one. For example:
% Assuming you have a vector with the labels in an array called "classes" and your data (features) in a matrix called "myData".
for ii = 1:19;
   testProportion = (ii*5)/100;
   c = cvpartition(classes, 'holdout',testProportion);
   trainData = myData(training(c,1),:);
   testData  = myData(test(c,1),:);

   % Try your classifier here.
end
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!