【发布时间】:2014-10-13 01:22:18
【问题描述】:
我已经训练了一个有 5 个类的多类 svm 分类器,即svm(1)...svm(5).
然后我使用了 5 张在训练这些分类器时不习惯的图像进行测试。
然后使用它们各自的分类器测试这 5 张图像。即,如果从第一类中拍摄 5 张图像,则它们将针对同一类进行测试。
predict = svmclassify(svm(i_t),test_features);
预测生成一个 5 x 1 的向量来显示结果。
-1
1
1
1
-1
我将这些相加,然后将其插入对角矩阵。
理想情况下,当所有图像都正确分类时,它应该是一个对角线为 5 的对角矩阵。但结果很差。我的意思是在某些情况下我得到了否定的结果。我只是想验证这个糟糕的结果是否是因为我的混淆矩阵不准确,或者我是否应该使用其他一些特征提取器。
这是我写的代码
svm_table = [];
for i_t = 1:numel(svm)
test_folder = [Path_training folders(i_t).name '\']; %select writer
feature_count = 1; %Initialize count for feature vector accumulation
for j_t = 6:10 %these 5 images that were not used for training
[img,map] = imread([test_folder imlist(j_t).name]);
test_img = imresize(img, [100 100]);
test_img = imcomplement(test_img);
%Features extracted here for each image.
%The feature vector for each image is a 1 x 16 vector.
test_features(feature_count,:) = Features_extracted;
%The feature vectors are accumulated in a single matrix. Each row is an image
feature_count = feature_count + 1; % increment the count
end
test_features(isnan(test_features)) = 0; %locate Nan and replace with 0
%I was getting NaN in some images, which was causing problems with svm, so just replaced with 0
predict = svmclassify(svm(i_t),test_features); %produce column vector of preicts
svm_table(end+1,end+1) = sum(predict); %sum them and add to matrix diagonally
end
这就是我得到的。看起来像一个混淆矩阵,但结果很差。
-1 0 0 0 0
0 -1 0 0 0
0 0 3 0 0
0 0 0 1 0
0 0 0 0 1
所以我只想知道这里出了什么问题。我的混淆矩阵的实现。我测试 svm 的方式或我选择的功能。
【问题讨论】:
标签: matlab machine-learning classification svm feature-extraction