matlab - 朴素分类器matlab

标签 matlab machine-learning classification probability naivebayes

在 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)

这是一个例子:

enter image description here

请注意,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

虽然我不知道这到底是什么,而且我的代码中可能有这个错误,但我想我只是测试一下看看它输出了什么。

最佳答案

您正在对降维数据使用分类器。分类器应该稍微不精确,因为它需要概括。在降维阶段,您会丢失信息,这也会导致分类性能下降。

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

至于混淆矩阵的使用。 C(3,4)=79 仅意味着对于 79 个数据点,类应该是 3,它们被归类为 4 类。完整的矩阵表明您的分类器适用于 1 类和2 但第 3 类有问题。其余类几乎没有数据,因此很难判断分类器对它们的效果如何。

关于matlab - 朴素分类器matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11554938/

相关文章:

Tensorflow - tf.variable_scope,GAN 的重用参数

machine-learning - 用于数值转换的机器学习

java - 稀疏数据的离散和连续分类器

matlab - 减少像素的局部邻域

algorithm - 从 Delaunay 三角剖分获得的三角形集合中获取具有共享边的三角形对

python - 多输出回归

python - Tensorflow 运行之间的准确性保持相同

java - 每 T 秒从 Java 运行 MATLAB

matlab - matlab中简单正弦波的傅里叶变换

perl - List::Util 'shuffle' 实际上是如何工作的?