Skip to content

Instantly share code, notes, and snippets.

@ricklentz
Created January 10, 2018 19:21
Show Gist options
  • Save ricklentz/ab63aaf9e485516d39f2b3b87c497674 to your computer and use it in GitHub Desktop.
Save ricklentz/ab63aaf9e485516d39f2b3b87c497674 to your computer and use it in GitHub Desktop.
import numpy as np
# Write a function that takes as input two lists Y, P,
# and returns the float corresponding to their cross-entropy.
def cross_entropy(Y, P):
cross_entropy = 0
for i in range(len(Y)):
cross_entropy -= Y[i]*np.log(P[i]) + (1-Y[i])*np.log(1-P[i])
return cross_entropy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment