MAT之SVM:SVM之分类预测根据已有大量数据集案例,输入已有病例的特征向量实现乳腺癌诊断高准确率预测

MAT之SVM:SVM之分类预测根据已有大量数据集案例,输入已有病例的特征向量实现乳腺癌诊断高准确率预测


输出结果

代码设计

load BreastTissue_data.mat 

n = randperm(size(matrix,1));  

train_matrix = matrix(n(1:80),:);
train_label = label(n(1:80),:);

test_matrix = matrix(n(81:end),:);
test_label = label(n(81:end),:);

[Train_matrix,PS] = mapminmax(train_matrix');
Train_matrix = Train_matrix';
Test_matrix = mapminmax('apply',test_matrix',PS);
Test_matrix = Test_matrix';

[c,g] = meshgrid(-10:0.2:10,-10:0.2:10);
[m,n] = size(c);
cg = zeros(m,n);
eps = 10^(-4);
v = 5;
bestc = 1;
bestg = 0.1;
bestacc = 0;
for i = 1:m
    for j = 1:n
        cmd = ['-v ',num2str(v),' -t 2',' -c ',num2str(2^c(i,j)),' -g ',num2str(2^g(i,j))];
        cg(i,j) = svmtrain(train_label,Train_matrix,cmd);
        if cg(i,j) > bestacc
            bestacc = cg(i,j);
            bestc = 2^c(i,j);
            bestg = 2^g(i,j);
        end
        if abs( cg(i,j)-bestacc )<=eps && bestc > 2^c(i,j)
            bestacc = cg(i,j);
            bestc = 2^c(i,j);
            bestg = 2^g(i,j);
        end
    end
end
cmd = [' -t 2',' -c ',num2str(bestc),' -g ',num2str(bestg)]; %

model = svmtrain(train_label,Train_matrix,cmd);

[predict_label_1,accuracy_1] = svmpredict(train_label,Train_matrix,model);
[predict_label_2,accuracy_2] = svmpredict(test_label,Test_matrix,model);
result_1 = [train_label predict_label_1];
result_2 = [test_label predict_label_2];

figure
plot(1:length(test_label),test_label,'r-*')
hold on
plot(1:length(test_label),predict_label_2,'b:o')
grid on
legend('真实类别','预测类别')
xlabel('乳腺样本测试集样本编号')
ylabel('乳腺样本测试集样本类别')
string = {'乳腺样本测试集与SVM算法预测乳腺病例结果对比(RBF核函数)—Jason niu';
          ['accuracy = ' num2str(accuracy_2(1)) '%']};
1
% title(string)

相关文章
SVM:SVM之Classification根据已有大量数据集案例,输入已有病例的特征向量实现乳腺癌诊断高准确率预测

(0)

相关推荐