TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Log Loss (Per-Sample)

Metrics & Evaluation
Easy

Compute binary log loss independently for every sample. Clip each predicted probability before applying the logarithm:

p^=min⁡(1−ε,max⁡(ε,p))\widehat p=\min(1-\varepsilon,\max(\varepsilon,p))p​=min(1−ε,max(ε,p)) L(y,p)=−[yln⁡(p^)+(1−y)ln⁡(1−p^)]L(y,p)=-\left[y\ln(\widehat p)+(1-y)\ln(1-\widehat p)\right]L(y,p)=−[yln(p​)+(1−y)ln(1−p​)]

Here, yyy is a binary target, ppp is its predicted probability, and ε\varepsilonε is eps. Use the natural logarithm and return a list of losses in input order.

Loading visualization...

Examples

Input: y_true = [1, 0, 1], y_pred = [0.9, 0.1, 0.8], eps = 1e-15

Output: [0.105361, 0.105361, 0.223144]

Explanation: Each confident correct prediction produces a small positive loss.

Input: y_true = [1, 0], y_pred = [1, 0], eps = 1e-15

Output: [0, 0]

Hint 1

Clip with max(eps, min(1 - eps, probability)).

Hint 2

Append -(y * math.log(p) + (1 - y) * math.log(1 - p)) for each pair.

Requirements

  • Clip every prediction to [eps, 1 - eps]
  • Compute binary log loss separately for each pair
  • Use the natural logarithm
  • Return a list of Python floats in sample order

Constraints

  • 1 <= len(y_true) == len(y_pred) <= 10000
  • Targets are 0 or 1
  • Predictions lie between 0 and 1
  • 0 < eps < 0.5
Try Similar Problems
Cross Entropy LossLogistic Regression TrainingSoftmax FunctionClassification MetricsMetrics F1 Micro

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Log Loss (Per-Sample)

Metrics & Evaluation
Easy

Compute binary log loss independently for every sample. Clip each predicted probability before applying the logarithm:

p^=min⁡(1−ε,max⁡(ε,p))\widehat p=\min(1-\varepsilon,\max(\varepsilon,p))p​=min(1−ε,max(ε,p)) L(y,p)=−[yln⁡(p^)+(1−y)ln⁡(1−p^)]L(y,p)=-\left[y\ln(\widehat p)+(1-y)\ln(1-\widehat p)\right]L(y,p)=−[yln(p​)+(1−y)ln(1−p​)]

Here, yyy is a binary target, ppp is its predicted probability, and ε\varepsilonε is eps. Use the natural logarithm and return a list of losses in input order.

Loading visualization...

Examples

Input: y_true = [1, 0, 1], y_pred = [0.9, 0.1, 0.8], eps = 1e-15

Output: [0.105361, 0.105361, 0.223144]

Explanation: Each confident correct prediction produces a small positive loss.

Input: y_true = [1, 0], y_pred = [1, 0], eps = 1e-15

Output: [0, 0]

Hint 1

Clip with max(eps, min(1 - eps, probability)).

Hint 2

Append -(y * math.log(p) + (1 - y) * math.log(1 - p)) for each pair.

Requirements

  • Clip every prediction to [eps, 1 - eps]
  • Compute binary log loss separately for each pair
  • Use the natural logarithm
  • Return a list of Python floats in sample order

Constraints

  • 1 <= len(y_true) == len(y_pred) <= 10000
  • Targets are 0 or 1
  • Predictions lie between 0 and 1
  • 0 < eps < 0.5
Try Similar Problems
Cross Entropy LossLogistic Regression TrainingSoftmax FunctionClassification MetricsMetrics F1 Micro

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.