LVQ神经网络的分类——乳腺肿瘤诊断(matlab实现)

目录

1 代码

2 结果 


1 代码

%% LVQ神经网络的分类——乳腺肿瘤诊断

%% 清空环境变量
clear all
clc
warning off
%% 导入数据
load data.mat
a=randperm(569);
Train=data(a(1:500),:);
Test=data(a(501:end),:);
% 训练数据
P_train=Train(:,3:end)';
Tc_train=Train(:,2)';
T_train=ind2vec(Tc_train);
% 测试数据
P_test=Test(:,3:end)';
Tc_test=Test(:,2)';
%% 创建网络
count_B=length(find(Tc_train==1));
count_M=length(find(Tc_train==2));
rate_B=count_B/500;
rate_M=count_M/500;
net=newlvq(minmax(P_train),20,[rate_B rate_M],0.01,'learnlv1');
% 设置网络参数
net.trainParam.epochs=1000;
net.trainParam.show=10;
net.trainParam.lr=0.1;
net.trainParam.goal=0.1;
%% 训练网络
net=train(net,P_train,T_train);
%% 仿真测试
T_sim=sim(net,P_test);
Tc_sim=vec2ind(T_sim);
result=[Tc_sim;Tc_test]
%% 结果显示
total_B=length(find(data(:,2)==1));
total_M=length(find(data(:,2)==2));
number_B=length(find(Tc_test==1));
number_M=length(find(Tc_test==2));
number_B_sim=length(find(Tc_sim==1 & Tc_test==1));
number_M_sim=length(find(Tc_sim==2 &Tc_test==2));
disp(['病例总数:' num2str(569)...
      '  良性:' num2str(total_B)...
      '  恶性:' num2str(total_M)]);
disp(['训练集病例总数:' num2str(500)...
      '  良性:' num2str(count_B)...
      '  恶性:' num2str(count_M)]);
disp(['测试集病例总数:' num2str(69)...
      '  良性:' num2str(number_B)...
      '  恶性:' num2str(number_M)]);
disp(['良性乳腺肿瘤确诊:' num2str(number_B_sim)...
      '  误诊:' num2str(number_B-number_B_sim)...
      '  确诊率p1=' num2str(number_B_sim/number_B*100) '%']);
disp(['恶性乳腺肿瘤确诊:' num2str(number_M_sim)...
      '  误诊:' num2str(number_M-number_M_sim)...
      '  确诊率p2=' num2str(number_M_sim/number_M*100) '%']);

%% LVQ神经网络的分类——乳腺肿瘤诊断

%% 清空环境变量
clear all
clc
warning off
%% 导入数据
load data.mat
a=randperm(569);
Train=data(a(1:500),:);
Test=data(a(501:end),:);
% 训练数据
P_train=Train(:,3:end)';
Tc_train=Train(:,2)';
T_train=ind2vec(Tc_train);
% 测试数据
P_test=Test(:,3:end)';
Tc_test=Test(:,2)';
%% 创建网络
count_B=length(find(Tc_train==1));
count_M=length(find(Tc_train==2));
rate_B=count_B/500;
rate_M=count_M/500;
net=newlvq(minmax(P_train),20,[rate_B rate_M],0.01,'learnlv1');
% 设置网络参数
net.trainParam.epochs=1000;
net.trainParam.show=10;
net.trainParam.lr=0.1;
net.trainParam.goal=0.1;
%% 训练网络
net=train(net,P_train,T_train);
%% 仿真测试
T_sim=sim(net,P_test);
Tc_sim=vec2ind(T_sim);
result=[Tc_sim;Tc_test]
%% 结果显示
total_B=length(find(data(:,2)==1));
total_M=length(find(data(:,2)==2));
number_B=length(find(Tc_test==1));
number_M=length(find(Tc_test==2));
number_B_sim=length(find(Tc_sim==1 & Tc_test==1));
number_M_sim=length(find(Tc_sim==2 &Tc_test==2));
disp(['病例总数:' num2str(569)...
      '  良性:' num2str(total_B)...
      '  恶性:' num2str(total_M)]);
disp(['训练集病例总数:' num2str(500)...
      '  良性:' num2str(count_B)...
      '  恶性:' num2str(count_M)]);
disp(['测试集病例总数:' num2str(69)...
      '  良性:' num2str(number_B)...
      '  恶性:' num2str(number_M)]);
disp(['良性乳腺肿瘤确诊:' num2str(number_B_sim)...
      '  误诊:' num2str(number_B-number_B_sim)...
      '  确诊率p1=' num2str(number_B_sim/number_B*100) '%']);
disp(['恶性乳腺肿瘤确诊:' num2str(number_M_sim)...
      '  误诊:' num2str(number_M-number_M_sim)...
      '  确诊率p2=' num2str(number_M_sim/number_M*100) '%']);

 

2 结果 


result =

  1 至 18 列

     1     2     1     2     2     1     1     1     1     1     1     1     2     2     2     2     1     1
     1     2     1     2     2     1     1     1     1     2     1     1     2     2     2     2     1     1

  19 至 36 列

     1     1     1     1     1     1     2     1     1     1     1     1     1     1     2     1     2     1
     1     2     1     2     1     1     2     2     1     1     1     1     1     1     2     1     2     1

  37 至 54 列

     1     1     1     2     2     2     1     1     1     2     1     1     1     2     2     1     1     2
     1     1     1     2     2     2     1     2     1     2     1     1     2     2     2     1     1     2

  55 至 69 列

     1     1     1     1     1     1     1     1     1     1     1     1     2     1     2
     1     2     1     1     1     1     1     1     1     1     1     2     2     1     2

病例总数:569  良性:357  恶性:212
训练集病例总数:500  良性:315  恶性:185
测试集病例总数:69  良性:42  恶性:27
良性乳腺肿瘤确诊:42  误诊:0  确诊率p1=100%
恶性乳腺肿瘤确诊:19  误诊:8  确诊率p2=70.3704%
>> 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值