Premium problem121. Binary Cross-Entropy

Easy Locked

Given true labels y (0 or 1) and predicted probabilities, return the mean binary cross-entropy.

L=−1n∑i[yilog⁡pi+(1−yi)log⁡(1−pi)]L = -\frac{1}{n}\sum_i \bigl[y_i \log p_i + (1-y_i)\log(1-p_i)\bigr]

This is the negative log-likelihood of the Bernoulli model: minimising the loss and maximising the likelihood are the same operation.

Input

y = [1, 0, 1]
probabilities = [0.9, 0.1, 0.8]

Output

0.14462152754328741

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)