SVM分类器混淆问题

时间:2018-12-12 13:32:56

标签: matlab classification svm confusion-matrix

这是我的代码:

num_classes = [1 2 4 5 11];
num_split = 5;

        for i=1:num_split

            current_train_data = ....;
            current_train_labes = ....;
            current_test_data = ....;
            current_test_labes = ....;

            SVMModels = cell(length(num_classes),1);
            Scores = zeros(size(current_test_data,1),length(num_classes));

            for j = 1:length(num_classes)
                indx = current_train_labes==num_classes(1,j);
                SVMModels{j} = fitcsvm(current_train_data,indx,'Standardize',true,'KernelFunction','RBF',...
                    'KernelScale','auto');
                [~,score] = predict(SVMModels{j},current_test_data);
                Scores(:,j) = score(:,2);

            end

            [~,predictions] = max(Scores,[],2);
            results = predictions ==current_test_labes;
            class_accuracy = [];
            for l=1:length(num_classes)
                true_positives = current_test_labes == num_classes(1,l);
                class_accuracy = [class_accuracy; sum(predictions(true_positives) == num_classes(1,l))/size(labels_test{l,1},1)];

            end

            final_results{eva,1} = (sum(results))/size(current_test_labes,1);
            final_results{eva,2} = mean(class_accuracy);
            final_results{eva,3} = confusionmat(current_test_labes,predictions);
    end

但是最终的混淆器还包含第3列和第3行,这些列不应存在。为什么?混乱垫的行和列应代表num_classes中包含的数字,因此应为5x5矩阵,但是输出为6x6矩阵。此外,第三行包含所有为零的值,而第3列预测值。您如何预测最初不存在的值?

0 个答案:

没有答案