3
当在matlab中测试朴素分类器时,即使我对相同的样本数据进行了训练和测试,我也得到了不同的结果,但我想知道我的代码是否正确,并且有人可以帮助解释为什么?天真的分类器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
虽然我不知道这是什么其实是我可能得到这个错误在我的代码,但我想我只是测试,看看它输出。
zscore标准化呢?这应该保存吗? – 2012-07-19 15:50:07
@JungleBoogie zscore标准化当然不是一个坏主意,因为它使您的分类方法在数值上稳定。请记住,看不见的数据必须经历相同的转换。准确地说:您需要从应用于训练数据的zscore函数中提取转换矩阵。将zscore应用于测试数据将导致使用不同的转换。 – denahiro 2012-07-20 06:50:17