MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   how to use the NaiveBayes.fit for classification in matlab? (https://www.labfans.com/bbs/showthread.php?t=22142)

poster 2019-11-26 03:41

how to use the NaiveBayes.fit for classification in matlab?
 
<p>I'm using Naive Bayes classifier:</p>

<pre><code> for i=1 :100
load('datas3.mat');
data=datas3;
[n,m]=size(data);
rows=(1:n);
testcount=floor((0.2)*n);
acc1=0; SenAr=0; SpeAr=0; MCCAr=0;
kk=10;
for k=1: kk
test_rows=randsample(rows,testcount);
train_rows=setdiff(rows,test_rows);
test=data(test_rows,:);
train=data(train_rows,:);
xtest=test(:,1:m-1);
ytest=test(:,m);
xtrain=train(:,1:m-1);
ytrain=train(:,m);
NB=NaiveBayes.fit(xtrain,ytrain);
out=NB.predict(xtest);
</code></pre>

<p>these errors were shown:
Warning: NaiveBayes will be removed in a future release. Use fitcnb instead. </p>

<blockquote>
<p>In NaiveBayes.fit (line 8)
In accu (line 30)
Error using NaiveBayes.fit>gaussianFit (line 373)
The within-class variance in each feature of TRAINING must be positive. The within-class variance
in feature 1 in class 0
are not positive.
Error in NaiveBayes.fit (line 337)
obj = gaussianFit(obj, training, gindex);
Error in accu (line 30)
NB=NaiveBayes.fit(xtrain,ytrain);</p>
</blockquote>

<p>I'll be very grateful to have your opinions. Thanks. </p>



[url=https://stackoverflow.com/questions/59038826/how-to-use-the-naivebayes-fit-for-classification-in-matlab]More answer...[/url]


所有时间均为北京时间。现在的时间是 23:25

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.