DataLane

25. Binary cross-entropy

hardProNot started~14 minPythonImplement binary_cross_entropy()

Asked in screens shaped like: OpenAI, Anthropic

Mean binary cross-entropy of labels y in {0,1} and probabilities p in (0,1), rounded to 4 decimals. Use natural log.

Examples

  • Example 1

    Input: { "y": [1, 0], "p": [0.9, 0.1] }
    Output: 0.1054

Constraints

  • p is in (0, 1); y is 0 or 1

Python editor

Loading Python engine…

Ctrl/Cmd + Enter submits

Run your code to see stdout.

Pro problem

Hard problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close