Skip to content

Instantly share code, notes, and snippets.

@PyDataBlog
Last active December 4, 2020 18:11
Show Gist options
  • Select an option

  • Save PyDataBlog/5e1c6907f5bd58e460745be415b5543c to your computer and use it in GitHub Desktop.

Select an option

Save PyDataBlog/5e1c6907f5bd58e460745be415b5543c to your computer and use it in GitHub Desktop.
"""
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