天真的分类器matlab

问题描述 投票:3回答:1

当在matlab中测试天真分类器时,即使我在相同的样本数据上进行了训练和测试,我得到了不同的结果,我想知道我的代码是否正确以及是否有人可以帮助解释为什么这样做?

%% dimensionality reduction 
columns = 6
[U,S,V]=svds(fulldata,columns);

%% randomly select dataset
rows = 1000;
columns = 6;

%# pick random rows
indX = randperm( size(fulldata,1) );
indX = indX(1:rows)';

%# pick random columns
%indY = randperm( size(fulldata,2) );
indY = indY(1:columns);

%# filter data
data = U(indX,indY);

%% apply normalization method to every cell
data = zscore(data);

%create a training set the same as datasample
training_data = data;

%match the class labels to the corresponding rows
target_class = classlabels(indX,:)

%classify the same data sample to check if naive bayes works
class  = classify(data, training_data, target_class, 'diaglinear')
confusionmat(test_class, class)

这是一个例子:

注意它有ipsweep,泪珠和背部与正常交通混合。我还没有进入分类看不见的数据的阶段,但我只是想测试它是否会对相同的数据进行分类。

混淆矩阵输出:

ans =

   537     0     0     0     0     0     0     1     0
     0   224     0     0     0     1     0     1     0
     0     0    91    79     0    17    24     4     0
     0     0     0     8     0     0     2     0     0
     0     0     0     0     3     0     0     0     0
     0     0     0     0     0     1     0     0     0
     0     0     0     0     0     0     2     0     0
     0     0     0     0     0     0     0     3     0
     0     0     0     0     0     1     0     0     1

虽然我不知道这实际上是什么,我可能在我的代码中弄错了但我想我只是测试看它输出什么。

matlab machine-learning classification probability naivebayes
1个回答
5
投票

您正在使用降维数据的分类器。分类器意味着稍微不精确,因为它需要概括。在维度降低阶段,您将丢失信息,这也会导致分类性能降低。

即使在训练集上也不要期望完美的表现,这将是一个过度拟合的坏情况。

至于混淆矩阵的使用。 C(3,4)=79仅仅意味着79个数据点,该类应为3,并且它们被归类为第4类。完整的矩阵表明你的分类器适用于1级和2级,但是在3级时遇到问题。其余的类都有几乎没有数据,所以很难判断分类器对它们有多好。

© www.soinside.com 2019 - 2024. All rights reserved.