computeap.m

来自「一款数据挖掘的软件」· M 代码 · 共 21 行

M
21
字号
% ComputeAP: calculate the average precision
% 
% Parameters:
% Y_prob: array of predicted probability
% Y_test: array of true labels
% class_set: set of all possible labels

function AvgPrec = ComputeAP(Y_prob, Y_test, class_set)

[junk, Index] = sort(-Y_prob);
TrueLabel = Y_test(Index);
AvgPrec = 0;
NumPos = 0;
for j = 1:length(TrueLabel)
    NumPos = NumPos + (TrueLabel(j) == class_set(1));
    AvgPrec = AvgPrec + (TrueLabel(j) == class_set(1)) * NumPos / j;
end;
if (sum(TrueLabel == class_set(1)) ~= 0) 
	AvgPrec = AvgPrec / sum(TrueLabel == class_set(1));
end;
	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?