|
vl00bnu5af064015136316.png (3.63 KB, 下載次數(shù): 0)
下載附件
保存到相冊
vl00bnu5af064015136316.png
2024-9-9 17:21 上傳
點(diǎn)擊上方藍(lán)字關(guān)注我們
ogmmbxdf5xe64015136416.png (6.45 KB, 下載次數(shù): 1)
下載附件
保存到相冊
ogmmbxdf5xe64015136416.png
2024-9-9 17:21 上傳
注明:此推文來自公眾號(hào)Lvy的口袋,歡迎大家關(guān)注Lvy小姐姐公眾號(hào)~ 多種算法對比圖是常用的科研繪圖,你知道幾種合適的繪圖樣式呢?
ej305liyqkm64015136516.png (5.32 KB, 下載次數(shù): 0)
下載附件
保存到相冊
ej305liyqkm64015136516.png
2024-9-9 17:21 上傳
1.真實(shí)值和預(yù)測值展示圖
qmrsytlusil64015136616.png (29.46 KB, 下載次數(shù): 0)
下載附件
保存到相冊
qmrsytlusil64015136616.png
2024-9-9 17:21 上傳
Tips:數(shù)據(jù)比較多、算法多的適合比較難看出實(shí)際的效果
數(shù)據(jù)就是各個(gè)算法預(yù)測值和真實(shí)值數(shù)據(jù)(工具箱直接導(dǎo)出)
data_pre_all=[]; %記錄預(yù)測數(shù)據(jù)load(' 多元線性回歸 17_Dec_11_34_33 train_result_train_vaild_test.mat')data1=data_Oriny_prey.y_test_predict;data_pre_all=[data_pre_all,data1];data_true=data_Oriny_prey.test_y;load('SSA麻雀搜索算法 隨機(jī)森林回歸 17_Dec_11_35_55 train_result_train_vaild_test.mat')data2=data_Oriny_prey.y_test_predict;data_pre_all=[data_pre_all,data2];load(' SVM-RF回歸 17_Dec_11_37_18 train_result_train_vaild_test.mat')data3=data_Oriny_prey.y_test_predict;data_pre_all=[data_pre_all,data3];load(' MLP回歸 17_Dec_11_38_31 train_result_train_vaild_test.mat')data4=data_Oriny_prey.y_test_predict;data_pre_all=[data_pre_all,data4];load(' LSTM回歸 17_Dec_11_40_29 train_result_train_vaild_test.mat')data5=data_Oriny_prey.y_test_predict;data_pre_all=[data_pre_all,data5];str={'真實(shí)值','多元線性回歸','SSA麻雀搜索算法 隨機(jī)森林回歸','SVM-RF回歸' ,'MLP回歸','LSTM回歸'};figure('Units', 'pixels', ... 'Position', [300 300 860 375]);plot(data_true,'--*') hold onfor i=1:size(data_pre_all,2) plot(data_pre_all(:,i)) hold on endlegend(str)set (gca,"FontSize",12,'LineWidth',1.2)box offlegend Box off
2.誤差柱狀對比圖
pl5ytrbvqua64015136716.png (10.54 KB, 下載次數(shù): 0)
下載附件
保存到相冊
pl5ytrbvqua64015136716.png
2024-9-9 17:21 上傳
Tips:建議選取量綱差別不大的誤差衡量指標(biāo),不然可能會(huì)有點(diǎn)丑
Test_all=[];for j=1:size(data_pre_all,2) y_test_predict=data_pre_all(:,j); test_y=data_true; test_MAE=sum(abs(y_test_predict-test_y))/length(test_y) ; test_MAPE=sum(abs((y_test_predict-test_y)./test_y))/length(test_y); test_MSE=(sum(((y_test_predict-test_y)).^2)/length(test_y)); test_RMSE=sqrt(sum(((y_test_predict-test_y)).^2)/length(test_y)); test_R2= 1 - (norm(test_y - y_test_predict)^2 / norm(test_y - mean(test_y))^2); Test_all=[Test_all;test_MAE test_MAPE test_MSE test_RMSE test_R2];end%%str={'真實(shí)值','多元線性回歸','SSA麻雀搜索算法 隨機(jī)森林回歸','SVM-RF回歸' ,'MLP回歸','LSTM回歸'};str1=str(2:end);str2={'MAE','MAPE','MSE','RMSE','R2'};data_out=array2table(Test_all);data_out.Properties.VariableNames=str2;data_out.Properties.RowNames=str1;disp(data_out)%% 柱狀圖 MAE MAPE RMSE 柱狀圖適合量綱差別不大的color= [0.1569 0.4706 0.7098 0.6039 0.7882 0.8588 0.9725 0.6745 0.5490 0.8549 0.9373 0.8275 0.7451 0.7216 0.8627 0.7843 0.1412 0.1373 1.0000 0.5333 0.5176 0.5569 0.8118 0.7882 1.0000 0.5333 0.5176];figure('Units', 'pixels', ... 'Position', [300 300 660 375]);plot_data_t=Test_all(:,[1,2,4])';b=bar(plot_data_t,0.8);hold on
for i = 1 : size(plot_data_t,2) x_data(:, i) = b(i).XEndPoints'; end
for i =1:size(plot_data_t,2)b(i).FaceColor = color(i,:);b(i).EdgeColor=[0.6353 0.6314 0.6431];b(i).LineWidth=1.2;end
for i = 1 : size(plot_data_t,1)-1 xilnk=(x_data(i, end)+ x_data(i+1, 1))/2; b1=xline(xilnk,'--','LineWidth',1.2); hold onend
ax=gca;legend(b,str1,'Location','best')ax.XTickLabels ={'MAE', 'MAPE', 'RMSE'};set(gca,"FontSize",12,"LineWidth",2)box offlegend box off
3.誤差散點(diǎn)對比圖
nzrpuymu3hb64015136816.png (11.89 KB, 下載次數(shù): 0)
下載附件
保存到相冊
nzrpuymu3hb64015136816.png
2024-9-9 17:21 上傳
Tips:可以任意選擇兩個(gè)誤差衡量維度
figureplot_data_t1=Test_all(:,[1,5])';MarkerType={'s','o','pentagram','^','v'};for i = 1 : size(plot_data_t1,2) scatter(plot_data_t1(1,i),plot_data_t1(2,i),120,MarkerType{i},"filled") hold onendset(gca,"FontSize",12,"LineWidth",2)box offlegend box offlegend(str1,'Location','best')xlabel('MAE')ylabel('R2')grid on
4.誤差密度散點(diǎn)圖
0fss3hbhxek64015136916.png (115.77 KB, 下載次數(shù): 0)
下載附件
保存到相冊
0fss3hbhxek64015136916.png
2024-9-9 17:21 上傳
figure('Units', 'pixels', ... 'Position', [150 150 920 500]);for i=1:5 subplot(2,3,i) n=50; X=double(data_true); Y=double(data_pre_all(:,i)); M=polyfit(X,Y,1); Y1=polyval(M,X); XList=linspace(min(X),max(X),n); YList=linspace(min(Y),max(Y),n); [XMesh,YMesh]=meshgrid(XList,YList); F=ksdensity([X,Y],[XMesh(:),YMesh(:)]); ZMesh=reshape(F,size(XMesh)); H=interp2(double(XMesh),double(YMesh),double(ZMesh),X,Y); scatter(data_true,data_pre_all(:,i),35,'filled','CData',H,'MarkerFaceAlpha',.5); hold on plot(X(1:10:end),Y1(1:10:end),'--','LineWidth',1.2) hold on str_label=[str1{1,i},' ','R2=',num2str(Test_all(i,end))]; title(str_label) set(gca,"FontSize",10,"LineWidth",1.5) xlabel('true') ylabel('predict')end
5.誤差雷達(dá)圖
pr1f54r4ujc64015137017.png (17.38 KB, 下載次數(shù): 0)
下載附件
保存到相冊
pr1f54r4ujc64015137017.png
2024-9-9 17:21 上傳
Tips:為了讓圖片更美觀將多個(gè)維度評價(jià)指標(biāo)進(jìn)行歸一化處理了
figure('Units', 'pixels', ... 'Position', [150 150 520 500]);Test_all1=Test_all./sum(Test_all); %把各個(gè)指標(biāo)歸一化到一個(gè)量綱Test_all1(:,end)=1-Test_all(:,end);RC=radarChart(Test_all1);str3={'A-MAE','A-MAPE','A-MSE','A-RMSE','1-R2'};RC.PropName=str3;RC.ClassName=str1;RC=RC.draw(); RC.legend();colorList=[78 101 155; 138 140 191; 184 168 207; 231 188 198; 253 207 158; 239 164 132; 182 118 108]./255;for n=1:RC.ClassNum RC.setPatchN(n,'Color',colorList(n,:),'MarkerFaceColor',colorList(n,:))end
本圖參考了公眾號(hào):slandarer隨筆
https://mp.weixin.qq.com/s/8Lu7yBs3cLlZk9bPStdgUA
調(diào)用函數(shù)
classdef radarChart% @Author : slandarer% 公眾號(hào) : slandarer隨筆% 知乎 : hikari
properties ax;arginList={'ClassName','PropName','Type'} XData;RTick=[];RLim=[];SepList=[1,1.2,1.5,2,2.5,3,4,5,6,8] Type='Line'; PropNum;ClassNum ClassName={}; PropName={};
BC=[198,199,201; 38, 74, 96; 209, 80, 51; 241,174, 44; 12,13,15; 102,194,165; 252,140, 98; 142,160,204; 231,138,195; 166,217, 83; 255,217, 48; 229,196,148; 179,179,179]./255;
% 句柄 ThetaTickHdl;RTickHdl;RLabelHdl;LgdHdl;PatchHdl;PropLabelHdl;BkgHdl end
methods function obj=radarChart(varargin) if isa(varargin{1},'matlab.graphics.axis.Axes') obj.ax=varargin{1};varargin(1)=[]; else obj.ax=gca; end % 獲取版本信息 tver=version('-release'); verMatlab=str2double(tver(1:4))+(abs(tver(5))-abs('a'))/2; if verMatlab hold on else hold(obj.ax,'on') end
obj.XData=varargin{1};varargin(1)=[]; obj.PropNum=size(obj.XData,2); obj.ClassNum=size(obj.XData,1); obj.RLim=[0,max(obj.XData,[],[1,2])];
% 獲取其他信息 for i=1:2:(length(varargin)-1) tid=ismember(obj.arginList,varargin{i}); if any(tid) obj.(obj.arginList{tid})=varargin{i+1}; end end if isempty(obj.ClassName) for i=1:obj.ClassNum obj.ClassName{i}=['class ',num2str(i)]; end end if isempty(obj.PropName) for i=1:obj.PropNum obj.PropName{i}=['prop ',num2str(i)]; end end help radarChart end
function obj=draw(obj) obj.ax.XLim=[-1,1]; obj.ax.YLim=[-1,1]; obj.ax.XTick=[]; obj.ax.YTick=[]; obj.ax.XColor='none'; obj.ax.YColor='none'; obj.ax.PlotBoxAspectRatio=[1,1,1]; % 繪制背景圓形 tt=linspace(0,2*pi,200); obj.BkgHdl=fill(cos(tt),sin(tt),[252,252,252]./255,'EdgeColor',[200,200,200]./255,'LineWidth',1); % 繪制Theta刻度線 tn=linspace(0,2*pi,obj.PropNum+1);tn=tn(1:end-1); XTheta=[cos(tn);zeros([1,obj.PropNum]);nan([1,obj.PropNum])]; YTheta=[sin(tn);zeros([1,obj.PropNum]);nan([1,obj.PropNum])]; obj.ThetaTickHdl=plot(XTheta(:),YTheta(:),'Color',[200,200,200]./255,'LineWidth',1); % 繪制R刻度線 if isempty(obj.RTick) dr=diff(obj.RLim); sepR=dr./3; multiE=ceil(log(sepR)/log(10)); sepR=sepR.*10^(1-multiE); sepR=obj.SepList(find(sepR
sepNum=floor(dr./sepR); obj.RTick=obj.RLim(1)+(0:sepNum).*sepR; if obj.RTick(end)~=obj.RLim(2) obj.RTick=[obj.RTick,obj.RLim]; end end obj.RLim(obj.RLim obj.RLim(obj.RLim>obj.RLim(2))=[];
XR=cos(tt').*(obj.RTick-obj.RLim(1))./diff(obj.RLim);XR=[XR;nan([1,length(obj.RTick)])]; YR=sin(tt').*(obj.RTick-obj.RLim(1))./diff(obj.RLim);YR=[YR;nan([1,length(obj.RTick)])]; obj.RTickHdl=plot(XR(:),YR(:),'Color',[200,200,200]./255,'LineWidth',1.1,'LineStyle','--');
% 繪制雷達(dá)圖 for i=1:size(obj.XData,1) XP=cos(tn).*(obj.XData(i,:)-obj.RLim(1))./diff(obj.RLim); YP=sin(tn).*(obj.XData(i,:)-obj.RLim(1))./diff(obj.RLim); switch obj.Type case 'Line' obj.PatchHdl(i)=plot([XP,XP(1)],[YP,YP(1)],... 'Color',obj.BC(mod(i-1,size(obj.BC,1))+1,:),'Marker','o',... 'LineWidth',1.8,'MarkerFaceColor',obj.BC(mod(i-1,size(obj.BC,1))+1,:)); case 'Patch' obj.PatchHdl(i)=patch(XP,YP,obj.BC(mod(i-1,size(obj.BC,1))+1,:),... 'EdgeColor',obj.BC(mod(i-1,size(obj.BC,1))+1,:),'FaceAlpha',.2,... 'LineWidth',1.8);
end end
% 繪制R標(biāo)簽文本 tnr=(tn(1)+tn(2))/2; for i=1:length(obj.RTick) obj.RLabelHdl(i)=text(cos(tnr).*(obj.RTick(i)-obj.RLim(1))./diff(obj.RLim),... sin(tnr).*(obj.RTick(i)-obj.RLim(1))./diff(obj.RLim),... sprintf('%.2f',obj.RTick(i)),'FontName','Arial','FontSize',11); end
% 繪制屬性標(biāo)簽 for i=1:obj.PropNum obj.PropLabelHdl(i)=text(cos(tn(i)).*1.1,sin(tn(i)).*1.1,obj.PropName{i},... 'FontSize',12,'HorizontalAlignment','center'); end
end% ========================================================================= function obj=setBkg(obj,varargin) set(obj.BkgHdl,varargin{:}) end
% 繪制圖例 function obj=legend(obj) obj.LgdHdl=legend([obj.PatchHdl],obj.ClassName,'FontSize',12,'Location','best'); end % 設(shè)置圖例屬性 function obj=setLegend(obj,varargin) set(obj.LgdHdl,varargin{:}) end
% 設(shè)置標(biāo)簽 function obj=setPropLabel(obj,varargin) for i=1:obj.PropNum set(obj.PropLabelHdl(i),varargin{:}) end end function obj=setRLabel(obj,varargin) for i=1:length(obj.RLabelHdl) set(obj.RLabelHdl(i),varargin{:}) end end
% 設(shè)置軸 function obj=setRTick(obj,varargin) set(obj.RTickHdl,varargin{:}) end function obj=setThetaTick(obj,varargin) set(obj.ThetaTickHdl,varargin{:}) end
% 設(shè)置patch屬性 function obj=setPatchN(obj,N,varargin) set(obj.PatchHdl(N),varargin{:}) end end% @author : slandarer% 公眾號(hào) : slandarer隨筆% 知乎 : hikariend
6.誤差羅盤圖
iqtg2eutcb064015137117.png (25.42 KB, 下載次數(shù): 0)
下載附件
保存到相冊
iqtg2eutcb064015137117.png
2024-9-9 17:21 上傳
figure('Units', 'pixels', ... 'Position', [150 150 920 600]);t = tiledlayout('flow','TileSpacing','compact');for i=1:length(Test_all(:,1))nexttileth1 = linspace(2*pi/length(Test_all(:,1))/2,2*pi-2*pi/length(Test_all(:,1))/2,length(Test_all(:,1)));r1 = Test_all(:,i)';[u1,v1] = pol2cart(th1,r1);M=compass(u1,v1);for j=1:length(Test_all(:,1)) M(j).LineWidth = 2; M(j).Color = colorList(j,:);
end title(str2{i})set(gca,"FontSize",10,"LineWidth",1)end legend(M,str1,"FontSize",10,"LineWidth",1,'Box','off','Location','southoutside')
時(shí)序的和回歸的算法比較也是類似的,【領(lǐng)取數(shù)據(jù)和代碼方式】,在公眾號(hào)【Lvy的口袋】(下方鏈接直接進(jìn)行公眾號(hào))后臺(tái)回復(fù)關(guān)鍵詞【算法對比圖】領(lǐng)取,還有什么比較合適的對比圖可以私發(fā)小編看能不能復(fù)現(xiàn)奧~
ps.合適的繪圖之后可能會(huì)更新到工具箱中,全家桶大力更新中~早上車早實(shí)惠
全家桶系列
一鍵打包公眾號(hào)過去和未來所有的作品~持續(xù)更新中【獲取方式】掃碼獲取或者點(diǎn)擊鏈接
https://mbd.pub/o/bread/mbd-ZJabmJ9v
fmseaqilqkk64015137217.png (43.79 KB, 下載次數(shù): 1)
下載附件
保存到相冊
fmseaqilqkk64015137217.png
2024-9-9 17:21 上傳
3rvktt5ctip64015137317.png (259 Bytes, 下載次數(shù): 0)
下載附件
保存到相冊
3rvktt5ctip64015137317.png
2024-9-9 17:21 上傳
END
arpqvuoblx164015137417.png (258 Bytes, 下載次數(shù): 1)
下載附件
保存到相冊
arpqvuoblx164015137417.png
2024-9-9 17:21 上傳
vvyshanosit64015137517.jpg (16.92 KB, 下載次數(shù): 0)
下載附件
保存到相冊
vvyshanosit64015137517.jpg
2024-9-9 17:21 上傳
長按二維碼識(shí)別關(guān)注
往期精彩回顧
推薦 | 神器系列大更新!|一鍵實(shí)現(xiàn)百種高效算法|輕松解決評價(jià)、降維、聚類、回歸、分類、時(shí)序預(yù)測、多輸入多輸出問題推薦 | 一句命令實(shí)現(xiàn)神經(jīng)網(wǎng)絡(luò)超參數(shù)優(yōu)化推薦 | 四種降維方法及可視化 流2群【756559035】 |
|