All problems

Binary Cross-Entropy for One Example

mediumPythonLogistic Regression

Counting how often the late-delivery model is right tells Kestrel Freight almost nothing about how good it is. A model that says 51 per cent and a model that says 99 per cent score identically on a job that turns out late, and a model that says 99 per cent on a job that arrives on time is not merely wrong, it is wrong at the top of its voice. The measure the team scores with is log loss, also called binary cross-entropy: it charges a prediction by how much probability it put on the outcome that actually happened, and the charge is the negative natural logarithm of that probability. Certainty that turns out misplaced is therefore expensive without limit, while an honest hedge is cheap.

Task: Print the log loss charged to this one prediction.

Input

One line holding two numbers separated by a single space: the true outcome, which is 1 if the delivery was late and 0 if it was not, and the probability of lateness the model gave the job, strictly between 0 and 1.

Output

One line holding the charge rounded to 4 decimal places, with no label. Use natural logarithms, not base 2 and not base 10, and print the charge as a positive number.

Example:

Input:
1 0.8

Output:
0.2231

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…