改写以下代码,使其能够分别计算四种故障类型的诊断准确率,然后让这四种故障类型分别画图:view (net) inputn_test=mapminmax('apply',input_test,inputps); an=sim(net,inputn_test); test_simu=mapminmax('reverse',an,outputps); test_simu=round(test_simu); % 就近取整 accTest = sum(test_simu==output_test)/length(output_test); figure plot(test_simu,'o','linewidth',1.5,'markersize',7) hold on plot(output_test,'+','linewidth',1.5) title(['BP测试集诊断准确率:' num2str(accTest*100) '%'],'fontsize',12) xlabel('样本','fontsize',12) ylabel('类型','fontsize',12) legend('实际类型','预测类型') grid on set(gca,'ytick',1:6,'yticklabel',names) set(gca,'linewidth',1.5)
时间: 2023-08-06 11:17:49 浏览: 48
以下是修改后的代码,其中假设有四种故障类型,分别为类型1、类型2、类型3和类型4:
```
% 计算四种故障类型的诊断准确率
accTest1 = sum(test_simu(output_test==1)==1)/sum(output_test==1);
accTest2 = sum(test_simu(output_test==2)==2)/sum(output_test==2);
accTest3 = sum(test_simu(output_test==3)==3)/sum(output_test==3);
accTest4 = sum(test_simu(output_test==4)==4)/sum(output_test==4);
% 分别画出四种故障类型的预测结果和实际结果
figure
subplot(2,2,1)
plot(test_simu(output_test==1),'o','linewidth',1.5,'markersize',7)
hold on
plot(output_test(output_test==1),'+','linewidth',1.5)
title(['诊断准确率:' num2str(accTest1*100) '%,类型1'],'fontsize',12)
xlabel('样本','fontsize',12)
ylabel('类型','fontsize',12)
legend('预测类型','实际类型')
grid on
set(gca,'ytick',1:4,'yticklabel',{'1','2','3','4'})
set(gca,'linewidth',1.5)
subplot(2,2,2)
plot(test_simu(output_test==2),'o','linewidth',1.5,'markersize',7)
hold on
plot(output_test(output_test==2),'+','linewidth',1.5)
title(['诊断准确率:' num2str(accTest2*100) '%,类型2'],'fontsize',12)
xlabel('样本','fontsize',12)
ylabel('类型','fontsize',12)
legend('预测类型','实际类型')
grid on
set(gca,'ytick',1:4,'yticklabel',{'1','2','3','4'})
set(gca,'linewidth',1.5)
subplot(2,2,3)
plot(test_simu(output_test==3),'o','linewidth',1.5,'markersize',7)
hold on
plot(output_test(output_test==3),'+','linewidth',1.5)
title(['诊断准确率:' num2str(accTest3*100) '%,类型3'],'fontsize',12)
xlabel('样本','fontsize',12)
ylabel('类型','fontsize',12)
legend('预测类型','实际类型')
grid on
set(gca,'ytick',1:4,'yticklabel',{'1','2','3','4'})
set(gca,'linewidth',1.5)
subplot(2,2,4)
plot(test_simu(output_test==4),'o','linewidth',1.5,'markersize',7)
hold on
plot(output_test(output_test==4),'+','linewidth',1.5)
title(['诊断准确率:' num2str(accTest4*100) '%,类型4'],'fontsize',12)
xlabel('样本','fontsize',12)
ylabel('类型','fontsize',12)
legend('预测类型','实际类型')
grid on
set(gca,'ytick',1:4,'yticklabel',{'1','2','3','4'})
set(gca,'linewidth',1.5)
```
该代码会生成一个包含四个子图的图形,每个子图表示一种故障类型的预测结果和实际结果,并且包含该故障类型的诊断准确率。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)