MATLAB Answers

Problem in Navie Bayes theorem code

20 views (last 30 days)
Ali Asghar
Ali Asghar on 12 Dec 2019
Commented: Ali Asghar on 14 Dec 2019
Dear all
I used the below code on 160x5 file and found it work correctly but now i change the file from 160x5 to 160x17 then it show error. Kindly look into it.
clear all, close all, clc
load('FeatureAngle000Musscle1.mat') % 160x17 size
X = FeaturesAngle000Muscle1(:,1:16);
Y = FeaturesAngle000Muscle1(:,17);
rng(1); % For reproducibility
Mdl2 = fitcnb(X,Y,...
'DistributionNames',{'normal','normal','kernel','kernel' 'normal','normal','kernel','kernel' 'normal','normal','kernel','kernel' 'normal','normal','kernel','kernel'},...
'ClassNames',{'HandGrip','HandOpen','HandRest','WristExtension','WristFlexion'});
Mdl2.DistributionParameters{1,2}
isLabels2 = resubPredict(Mdl2); % it generate the output/response of model
ConfusionMat2 = confusionchart(table2array(Y),isLabels2); % Y need to convert
showing error
Error using ClassificationNaiveBayes/fitNonMNDists (line 222)
A normal distribution cannot be fit for the combination of class HandGrip and predictor LD. The data has zero variance.
Error in ClassificationNaiveBayes (line 104)
this.DistributionParameters = fitNonMNDists(this);
Error in classreg.learning.FitTemplate/fit (line 258)
[varargout{1:nargout}] = this.MakeFitObject(X,Y,W,this.ModelParams,fitArgs{:});
Error in ClassificationNaiveBayes.fit (line 132)
this = fit(temp,X,Y);
Error in fitcnb (line 252)
this = ClassificationNaiveBayes.fit(X,Y,RemainingArgs{:});

  0 Comments

Sign in to comment.

Answers (2)

Hiro
Hiro on 12 Dec 2019
'ClassNames',{'HandGrip','HandOpen','HandRest','WristExtension','WristFlexion'});
the number of class labels is 5 but I guess yours is 17?

  1 Comment

Ali Asghar
Ali Asghar on 12 Dec 2019
In 1-16 Columns there are different features values of emg signals like RMS, VAR etc and in 17th column there is respective output like handopen, handclose etc
In 1-32 rows the 17th columns have Handopen
in 33-64 the the 17th columns have Handclose
etc

Sign in to comment.


Hiro
Hiro on 12 Dec 2019
I guess one of the distributions does not match what it is, i.e., variance is zero. In this case, Gaussian distributions cannot be fit anyway...

  1 Comment

Ali Asghar
Ali Asghar on 14 Dec 2019
What i can i do now, other than Gaussian...

Sign in to comment.