function [Metrics]=polygonareametric(ActualLabel, PredictedLabel,isPlot)
%%%%% WARNING %%%%%%%
%NUMERICALLY LARGER CLASS WILL BE AUTOMATICALLY ASSIGNED AS PositiveClass
%THIS IS BECAUSE OF THE FUNCTION OF perfcurve. IT REQUIRES LARGER CLASS AS PositiveClass.
% INTRODUCTION:
% This study proposes a stable and profound knowledge criterion that allows the performance of a classifier
% to be evaluated with only a single metric called as polygon area metric (PAM). This function is not only
% calculates PAM value, but also gives Classification Accuracy (CA), Sensitivity (SE), Specificity (SP),
% Kappa (K) and F measure metrics.
%
% CITATION INFORMATION:
% Please cite the following paper for the usage of PAM value:
% Aydemir O., A New Performance Evaluation Metric for Classifiers: Polygon Area Metric, Journal of Classification, (2020). https://doi.org/10.1007/s00357-020-09362-5
%
% USAGE OF THE FUNCTION:
% INPUTS;
% -ActualLabel: Actual label of the trials (samples), 1xN dimension binary labels
% -PredictedLabel: Predicted (estimated) label of the trials (samples), 1xN dimension binary labels
% -isPlot: A logical value indicating whether the resultant figure will be drawn. Default is true
%
% OUTPUT;
% -Metrics: This struct gives 7 evaluation metrics which are Polygon Area...
% (PA), Classification_Accuracy (CA), Sensitivity (SE), Specificity...
% (SP), AUC (AUC), Kappa (K), F_measure (F_M), respectively.
% AUC: Area under curve value, which should be obtained by Receiver operating characteristic (ROC), 0<AUC<1
%
% EXAMPLE;
% -ActualLabel=[1 1 1 1 1 0 0 0 0];
% -PredictedLabel=[1 1 1 0 0 0 0 0 1];
% -[Metrics]=polygonareametric(ActualLabel,PredictedLabel)
%Code introduction
if nargin<2
error('You have to supply all required input paremeters, which are ActualLabel, PredictedLabel')
end
if nargin < 3
isPlot = true;
end
%plotting the widest polygon
A1=1;
A2=1;
A3=1;
A4=1;
A5=1;
A6=1;
a=[-A1 -A2/2 A3/2 A4 A5/2 -A6/2 -A1];
b=[0 -(A2*sqrt(3))/2 -(A3*sqrt(3))/2 0 (A5*sqrt(3))/2 (A6*sqrt(3))/2 0];
if isPlot
figure
plot(a, b, '--bo','LineWidth',1.3)
axis([-1.5 1.5 -1.5 1.5]);
set(gca,'FontName','Times New Roman','FontSize',12);
hold on
%grid
end
% Calculating the True positive (TP), False Negative (FN), False Positive...
% (FP),True Negative (TN), Classification Accuracy (CA), Sensitivity (SE), Specificity (SP),...
% Kappa (K) and F measure (F_M) metrics
PositiveClass=max(ActualLabel);
NegativeClass=min(ActualLabel);
cp=classperf(ActualLabel,PredictedLabel,'Positive',PositiveClass,'Negative',NegativeClass);
CM=cp.DiagnosticTable;
TP=CM(1,1);
FN=CM(2,1);
FP=CM(1,2);
TN=CM(2,2);
CA=cp.CorrectRate;
SE=cp.Sensitivity; %TP/(TP+FN)
SP=cp.Specificity; %TN/(TN+FP)
Pr=TP/(TP+FP);
Re=TP/(TP+FN);
F_M=2*Pr*Re/(Pr+Re);
FPR=FP/(TN+FP);
TPR=TP/(TP+FN);
K=TP/(TP+FP+FN);
[X1,Y1,T1,AUC] = perfcurve(ActualLabel,PredictedLabel,PositiveClass);
%ActualLabel(1) means that the first class is assigned as positive class
%plotting the calculated CA, SE, SP, AUC, K and F_M on polygon
x=[-CA -SE/2 SP/2 AUC K/2 -F_M/2 -CA];
y=[0 -(SE*sqrt(3))/2 -(SP*sqrt(3))/2 0 (K*sqrt(3))/2 (F_M*sqrt(3))/2 0];
if isPlot
plot(x, y, '-ko','LineWidth',1)
set(gca,'FontName','Times New Roman','FontSize',12);
% shadowFill(x,y,pi/4,80)
fill(x, y,[0.8706 0.9216 0.9804])
end
%calculating the PAM value
% Get the number of vertices
n = length(x);
% Initialize the area
p_area = 0;
% Apply the formula
for i = 1 : n-1
p_area = p_area + (x(i) + x(i+1)) * (y(i) - y(i+1));
end
p_area = abs(p_area)/2;
%Normalization of the polygon area to one.
PA=p_area/2.59807;
if isPlot
%Plotting the Polygon
plot(0,0,'r+')
plot([0 -A1],[0 0] ,'--ko')
text(-A1-0.3, 0,'CA','FontWeight','bold','FontName','Times New Roman')
plot([0 -A2/2],[0 -(A2*sqrt(3))/2] ,'--ko')
text(-0.59,-1.05,'SE','FontWeight','bold','FontName','Times New Roman')
plot([0 A3/2],[0 -(A3*sqrt(3))/2] ,'--ko')
text(0.5, -1.05,'SP','FontWeight','bold','FontName','Times New Roman')
plot([0 A4],[0 0] ,'--ko')
text(A4+0.08, 0,'AUC','FontWeight','bold','FontName','Times New Roman')
plot([0 A5/2],[0 (A5*sqrt(3))/2] ,'--ko')
text(0.5, 1.05,'J','FontWeight','bold','FontName','Times New Roman')
plot([0 -A6/2],[0 (A6*sqrt(3))/2] ,'--ko')
text(-0.65, 1.05,'FM','FontWeight','bold','FontName','Times New Roman')
set(gca,'FontName','Times New Roman','FontSize',12);
grid
daspect([1 1 1])
end
Metrics.PA=PA;
Metrics.CA=CA;
Metrics.SE=SE;
Metrics.SP=SP;
Metrics.AUC=AUC;
Metrics.K=K;
Metrics.F_M=F_M;
categories = {'多边形面积PAM';'分类准确率';'灵敏度';'特异性';'曲线下面积AUC';'Kappa系数'; 'F_measure'};
printVar = cell(7,2);
printVar(:,1)=categories;
printVar(:,2)={PA, CA, SE, SP, AUC, K, F_M};
disp('预测结果打印:')
for i=1:length(categories)
fprintf('%23s: %.2f \n', printVar{i,1}, printVar{i,2})
end
遗传粒子群混合算法优化BP神经网络回归预测(GAPSO-BP),融合遗传算法的粒子群算法优化BP神经网络回归预测,多变量输入单输
![](https://csdnimg.cn/release/downloadcmsfe/public/img/starY.0159711c.png)
遗传粒子群混合算法优化BP神经网络回归预测(GAPSO-BP),融合遗传算法的粒子群算法优化BP神经网络回归预测,多变量输入单输出模型。
评价指标包括:R2、MAE、MSE、RMSE和MAPE等,代码质量极高,方便学习和替换数据。
![avatar](https://profile-avatar.csdnimg.cn/29fb0510661e41e5b896558967268110_qq_43916303.jpg!1)
智能算法及其模型预测
- 粉丝: 2539
- 资源: 871
最新资源
- 高阶AI指令大合集!.zip
- DeepSeek零基础到精通手册(保姆级教程).zip
- DeepSeek使用攻略.zip
- 【官网提示库】探索 DeepSeek 提示词样例,挖掘更多可能.zip
- 《7天精通DeepSeek实操手册》.zip
- 教大家如何使用Deepseek AI进行超级降维知识输出V1.0版.zip
- DeepSeek 15天指导手册-从入门到精通.zip
- 10天精通+DeepSeek+实操手册.zip
- 112页!DeepSeek 7大场景+50大案例+全套提示词 从入门到精通干货-202502.zip
- Deepseek+V3从零基础到精通学习手册(1).zip
- OMO2203class3面向对象.mp4
- 三相逆变器下垂控制参数调整与波形质量分析报告:直流侧电压800V,交流侧电压220V,开关频率达10kHz,模拟调频工况下性能表现优越,三相逆变器下垂控制参数调整与波形质量分析报告:直流侧电压800V
- 工具变量-上市公司企业绿色创新泡沫数据(1995-2023年).txt
- Simulink Simscape中的UR5机械臂三次多项式轨迹规划仿真:动态动画展示角度、力矩与运动参数图,六自由度UR5机械臂Simulink Simscape三次多项式轨迹规划仿真动画及数据图表
- 基于FPGA与Matlab算法的超声多普勒频移解调系统:DDS生成信号、混合与滤波处理、FFT运算及峰值搜索比对,基于FPGA和MATLAB的超声多普勒频移解调技术:DDS生成信号、混频处理、滤波、F
- 松下FP-XH双PLC 10轴摆盘程序范例:清晰分输出与调试、报警通信、启动复位,维纶通触摸屏操作,一年平稳运行经验分享,松下FP-XH双PLC 10轴摆盘程序范例:清晰思路,易学易懂,带触摸屏与通信