Last active
December 4, 2020 18:11
-
-
Save PyDataBlog/5e1c6907f5bd58e460745be415b5543c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Computes the log loss (binary cross entropy) of the current predictions. | |
| """ | |
| function calculate_cost(Ŷ, Y) | |
| m = size(Y, 2) | |
| epsilon = eps(1.0) | |
| # Deal with log(0) scenarios | |
| Ŷ_new = [max(i, epsilon) for i in Ŷ] | |
| Ŷ_new = [min(i, 1-epsilon) for i in Ŷ_new] | |
| cost = -sum(Y .* log.(Ŷ_new) + (1 .- Y) .* log.(1 .- Ŷ_new)) / m | |
| return cost | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment