一、指标解释
我在研究论文的时候观察到了一个性能指标,叫做PPTS(Peak percentage of threshold statistic),翻译过来是:阈值统计的峰值百分比。这篇论文中给出的定义为:
computes the average absolute relative error of predictands of the top γ% streamflow data.The lower the PPTS,the better the capability to forecast peak flow. Note that the recorded streamflow values are arranged in descending order to compute the PPTS and that the threshold level γ denotes the percentage of data selected from the beginning of the arranged data sequence. The parameter G is the number of values above the threshold level γ.
计算公式为:
可以从公式看到,这个PPTS其实就是 一个 平均绝对百分比误差(Mean Absolute Percentage Error,MAPE),但是是将原来的流量序列进行一个降序排列,选择top γ%的数据进行MAPE的计算。
二、计算设计
我利用这个概念自己设计了一个PPTS的计算
- 得到y_true(原始流量)的最大值y_max,与最小值y_min。
- 设置delta=y_max-y_min。
- 设置一个百分比γ,设阈值为Gamma,Gamma=y_min+p*delta
- 利用eff=np.where(y_true>Gamma)得到满足y_true>Gamma的元素所在的矩阵位置。
- 对满足条件的流量值计算相对误差的绝对值。
- 最后求取平均值即可
三、代码如下
// An highlighted block
def PPTS(y_true, y_pred):
"""
参数:
y_true -- 测试集目标真实值
y_pred -- 测试集目标预测值
返回:
mape -- MAPE 评价指标
"""
p=0.01
y_max=np.max(y_true)
y_min=np.min(y_true)
delta=y_max-y_min
Gamma = y_min+p*delta
mape=0
label= np.where(y_true > Gamma)
eff=label[0]
l=len(eff)
for i,a in enumerate(eff):
mape = mape+(np.abs((y_true[a,:] - y_pred[a,:]) / y_true[a,:]) * 100)
ppts = mape/ l
return ppts
四、小结
自己设计的这个指标与论文中的PPTS还是有一些不同的,它其实是计算了top(1-γ)的MAPE,不过同样能评估模型对峰值的计算性能了。