Skip to content

Instantly share code, notes, and snippets.

@Tooluloope
Created March 13, 2019 08:24
Show Gist options
  • Save Tooluloope/e4ab29b16994d72ea4c9d3e1f9d3ef1f to your computer and use it in GitHub Desktop.
Save Tooluloope/e4ab29b16994d72ea4c9d3e1f9d3ef1f to your computer and use it in GitHub Desktop.
def compute_cost(Al, Y):
"""
Arguments:
AL -- probability vector corresponding to your label predictions, shape (1, number of examples)
Y -- true "label" vector (for example: containing 0 if non-cat, 1 if cat), shape (1, number of examples)
Returns:
cost -- cross-entropy cost
"""
m = Y.shape[1]
cost = -1/m * np.sum(np.multiply(Y, np.log(Al)) + np.multiply((1-Y), np.log(1-Al)))
cost = np.squeeze(cost)
return cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment