All problems
Confidence Margin
Problem
Compute the confidence margin: the largest softmax probability minus the second largest for a vector of logits. Use a stable softmax.
The signature is confidence_margin(logits).
Hint
A large margin means the model strongly prefers one class over the runner-up.
Test cases
case 1
in: [[1,1]]
expected: 0
case 2
in: [[2,0]]
expected: 0.761594156
case 3
in: [[0,0,0]]
expected: 0
case 4
in: [[10,0]]
expected: 0.9999092043
Starter codePython
import math
def confidence_margin(logits):
# Your code here
pass4 test cases · run your code against them in the editor