All problems
Pinball Loss
Problem
Compute the mean pinball (quantile) loss for a forecast at quantile q. For each pair add q * (actual - forecast) when actual >= forecast, otherwise (q - 1) * (actual - forecast).
Return the average over all pairs, or 0.0 for an empty actual list.
Hint
The penalties on the two sides of the forecast are asymmetric unless q = 0.5.
Test cases
case 1
in: [[10,10],[12,8],0.5]
expected: 1
case 2
in: [[5],[7],0.9]
expected: 0.19999999999999996
case 3
in: [[5],[3],0.9]
expected: 1.8
case 4
in: [[1,2,3],[1,2,3],0.75]
expected: 0
Starter codePython
def pinball_loss(actual, forecast, q):
# Your code here
pass4 test cases · run your code against them in the editor