Log loss (binary cross-entropy) measures how far each predicted probability is from the actual label. A confident correct prediction has a loss near zero, while a confident wrong prediction has a very large loss.
Given a list of true binary labels and predicted probabilities, compute the per-sample log loss and return them as a list.
For each sample:
L(y,p)=−(y⋅ln(p^)+(1−y)⋅ln(1−p^))where:
p^=clip(p,ε,1−ε)Clipping prevents taking the log of zero. That is, bound p to be no smaller than epsilon and no larger than 1 - epsilon. Use a default epsilon of 1e-15.
Return a list of floats, one loss value per sample.
Input:
y_true = [1, 0, 1] y_pred = [0.9, 0.1, 0.8]
Output:
[0.10536051565782628, 0.10536051565782628, 0.22314355131420976]
High-confidence correct predictions produce small loss values.
Input:
y_true = [1, 0] y_pred = [1.0, 0.0]
Output:
[3.3306690738754696e-16, 3.3306690738754696e-16]
Predictions of exactly 0.0 and 1.0 are clipped to epsilon and 1-epsilon before computing the log.
Think about what happens when p = 0.0 or p = 1.0 and how to handle it before computing the logarithm.
The formula has two terms: one active when y=1, the other when y=0. Make sure both are always computed.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Log loss (binary cross-entropy) measures how far each predicted probability is from the actual label. A confident correct prediction has a loss near zero, while a confident wrong prediction has a very large loss.
Given a list of true binary labels and predicted probabilities, compute the per-sample log loss and return them as a list.
For each sample:
L(y,p)=−(y⋅ln(p^)+(1−y)⋅ln(1−p^))where:
p^=clip(p,ε,1−ε)Clipping prevents taking the log of zero. That is, bound p to be no smaller than epsilon and no larger than 1 - epsilon. Use a default epsilon of 1e-15.
Return a list of floats, one loss value per sample.
Input:
y_true = [1, 0, 1] y_pred = [0.9, 0.1, 0.8]
Output:
[0.10536051565782628, 0.10536051565782628, 0.22314355131420976]
High-confidence correct predictions produce small loss values.
Input:
y_true = [1, 0] y_pred = [1.0, 0.0]
Output:
[3.3306690738754696e-16, 3.3306690738754696e-16]
Predictions of exactly 0.0 and 1.0 are clipped to epsilon and 1-epsilon before computing the log.
Think about what happens when p = 0.0 or p = 1.0 and how to handle it before computing the logarithm.
The formula has two terms: one active when y=1, the other when y=0. Make sure both are always computed.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number