利用Python实现上述评价指标
时间: 2023-11-29 16:39:24 浏览: 37
以下是使用 Python 实现上述评价指标的示例代码:
```python
import numpy as np
def error_compute(y_pred_upper, y_pred_lower, y_tes, alpha):
# Ravel for ease of computation
y_pred_upper = y_pred_upper.ravel()
y_pred_lower = y_pred_lower.ravel()
y_tes = y_tes.ravel()
# Find out of bound indices for WS
idx_oobl = np.where((y_tes < y_pred_lower))[0] # 低于下限
idx_oobu = np.where((y_tes > y_pred_upper))[0] # 高于上限
picp = np.sum((y_tes > y_pred_lower) & (y_tes <= y_pred_upper)) / len(y_tes) * 100
ace = picp - (1 - alpha) * 100
pinaw = np.sum(y_pred_upper - y_pred_lower) / (np.max(y_tes) - np.min(y_tes)) / len(y_tes)
ws = np.sum(np.sum(-2 * alpha * (y_pred_upper - y_pred_lower)) +
np.sum(-4 * (y_pred_lower[idx_oobl] - y_tes[idx_oobl])) +
np.sum(-4 * (y_tes[idx_oobu] - y_pred_upper[idx_oobu]))) / len(y_tes)
print("PICP: {:.4f}%".format(picp))
print("ACE: {:.4f}".format(ace))
print("PINAW: {:.4f}".format(pinaw))
print("WS: {:.4f}".format(ws))
# 使用示例
y_pred_upper = np.array([2.5, 3.2, 4.1, 3.8])
y_pred_lower = np.array([1.8, 2.9, 3.7, 3.4])
y_tes = np.array([2.3, 3.0, 4.0, 3.5])
alpha = 0.05
error_compute(y_pred_upper, y_pred_lower, y_tes, alpha)
```
这段代码定义了一个 `error_compute()` 函数,并使用示例数据进行调用。您可以根据实际情况替换示例数据。函数会计算并打印出 PICP、ACE、PINAW 和 WS 的值。