在 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、teardrop 和 back与正常流量混合。我还没有到对看不见的数据进行分类的阶段,但我只是想测试它是否会对相同的数据进行分类。
混淆矩阵输出:
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
尽管我不知道这实际上是什么,而且我的代码中可能有这个错误,但我想我只是测试一下它的输出。