Search code examples
matlabmultilabel-classificationlinear-discriminant

How to exclude data with 0 variance in matlab implementation of Linear discriminant analysis


I am using Matlab to classify data using LDA.

  mdl = fitcdiscr(dbimgs1,indx,'DiscrimType','linear');
  C=predict(mdl,testimgs1);

I get the following error:

Predictor x741 has zero variance. Either exclude this predictor or set 'discrimType' to 'pseudoLinear' or 'diagLinear'.

I do not wish to use 'pseudoLinear' or 'diagLinear' as it degrades the performance. How can I exclude the zero predictor?


Solution

  •   delete_id=[];
      for id_var_chk=1:size(dbimgs1,2)
          if(var(dbimgs1(:,id_var_chk))<1)
                 delete_id=[delete_id,id_var_chk]
          end
      end
    

    The loop checks the variance of each column. The values with low variance are then deleted by:

     dbimgs1(:,delete_id_1(i))=[];