figure%打开一个图像窗口 subplot(2,1,1) plot(numa(step1+1:end),'k-') subplot(2,1,2) plot(y_pred,'b-')%黑色实线,点的形状为* hold on%继续画图 plot(output_test,'r--')%红色实线,点的形状为o hold off%停止画图 title('测试图')%标题 ylabel('类别')%Y轴名称 legend('测试值','实际值','Location','southeast')%标签 set(gca,'fontsize',12) set(gca,'YTick',0:1) set(gca,'YTickLabel',{'正常','异常'}) ylim([-0.2 1.2]) error1 = y_pred-output_test;%误差 figure plot(error1,'k-') title('测试误差图') set(gca,'fontsize',12) [MSE,RMSE,MBE,MAE ] =MSE_RMSE_MBE_MAE(output_test,y_pred); result_table = table; result_table.sim = y_pred'; result_table.true = output_test'; writetable(result_table,'./结果.csv')
时间: 2023-08-07 10:03:38 浏览: 90
这是一段 MATLAB 代码,用于绘制回归模型的预测结果和误差,并输出模型的性能指标和结果。具体解释如下:
- `figure`:打开一个新的图像窗口。
- `subplot(2,1,1)` 和 `subplot(2,1,2)`:将图像窗口分成两个子图,分别对应于回归模型的预测结果和真实输出值。
- `plot(numa(step1+1:end),'k-')`、`plot(y_pred,'b-')` 和 `plot(output_test,'r--')`:分别绘制预测结果、真实输出值和预测误差的折线图。
- `hold on` 和 `hold off`:控制绘图的持续性,即在绘制完 `plot(y_pred,'b-')` 后,使用 `hold on` 命令可以使绘图继续,然后绘制 `plot(output_test,'r--')`,最后使用 `hold off` 命令停止绘图。
- `title('测试图')`:设置图像的标题为“测试图”。
- `ylabel('类别')`:设置 Y 轴的标签为“类别”。
- `legend('测试值','实际值','Location','southeast')`:添加图例,并将其放置在图像的右下角(Southeast)位置。
- `set(gca,'fontsize',12)`、`set(gca,'YTick',0:1)` 和 `set(gca,'YTickLabel',{'正常','异常'})`:设置图像的字体大小、Y 轴的刻度值和标签。
- `ylim([-0.2 1.2])`:设置 Y 轴的范围为 [-0.2, 1.2]。
- `plot(error1,'k-')`:绘制预测误差的折线图。
- `title('测试误差图')`:设置图像的标题为“测试误差图”。
- `set(gca,'fontsize',12)`:设置图像的字体大小。
- `[MSE,RMSE,MBE,MAE ] =MSE_RMSE_MBE_MAE(output_test,y_pred)`:计算回归模型的性能指标,包括均方误差、均方根误差、平均偏差和平均绝对误差,并将其保存到变量中。
- `result_table = table; result_table.sim = y_pred'; result_table.true = output_test'; writetable(result_table,'./结果.csv')`:将预测结果和真实输出值保存到表格文件中,文件名为“结果.csv”。
阅读全文
相关推荐


















