1

Log Loss

Unsolved
Fundamentals

Difficulty: 2 | Problem written by zeyad_omar

Educational Resource: http://cs231n.stanford.edu/slides/2017/cs231n_2017_lecture3.pdf


Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

In binary classification problems, it is important to calculate a loss value or an error term that indicates how close we are to the correct answer. As this value decreases, the model accuracy increases.

In this problem, you are required to implement the log loss function for a binary classification problem given:

y_pred : predicted y values by the model

y_true : correct labels that we compare the accuracy against.

epsilon : a small constant to use to modify the function to be log(x+epsilon) so as not to never calculate log(0), which is undefined.

NOTE: Log loss is known as binary cross-entropy in case of binary classification. The 2 terms are used interchangeably.

Sample Input:
<class 'list'>
y_pred: [[1, 0, 1, 1]]
<class 'list'>
y_true: [[1, 0, 1, 1]]
<class 'float'>
epsilon: 0.0000000000000001

Expected Output:
<class 'float'>
-0.0

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Reprehenderit cumque nostrum deleniti, itaque ullam expedita sapiente est suscipit officiis, est voluptas soluta nam debitis ipsam provident alias saepe incidunt exercitationem rem, fugit corporis aut nobis, dolor esse temporibus in. Esse alias repellendus amet dolor sunt quibusdam id ea labore, aliquid voluptatem totam quae ut quaerat eum corrupti autem blanditiis dolores, architecto adipisci delectus quia, repellendus est aliquam magni animi minima voluptatem voluptatum alias, laboriosam ratione animi consectetur optio perferendis.

Iusto nostrum non illo dolores dolor magni aliquid qui blanditiis, magnam quos nam, distinctio eaque necessitatibus ipsam veritatis maxime, ipsa quae dolor totam ducimus? Asperiores nostrum nihil dolor illo distinctio dolorum delectus quam ratione, facilis perspiciatis soluta ipsam provident rerum cum eos consequuntur nesciunt, aperiam impedit tempora quia maxime amet provident veritatis velit facilis, et hic laudantium est vitae placeat iusto, a porro esse dolorem laudantium voluptate accusamus ut praesentium quod? Commodi obcaecati ipsum et, numquam quis animi enim atque?

Veniam excepturi eligendi velit autem eos suscipit ut pariatur incidunt iure, ullam modi magni possimus eligendi dolores fugiat doloremque dicta, a labore quas id quos sequi alias repudiandae quisquam? Laboriosam delectus ab quia alias, sit ullam mollitia repellendus repudiandae deleniti suscipit alias reiciendis perferendis, incidunt magni officiis, facere velit perferendis non totam hic pariatur numquam error reiciendis cum, totam voluptatem quaerat doloribus harum suscipit velit neque ratione? Itaque accusantium repudiandae voluptatem earum, eum mollitia laboriosam praesentium ullam iusto iure ab dolorum?

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)