Created
September 20, 2018 15:15
-
-
Save ImadDabbura/1a82e17d6a3ba9c554e07b808c78fc0c to your computer and use it in GitHub Desktop.
This file contains 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
def compute_cost_reg(AL, y, parameters, lambd=0): | |
# number of examples | |
m = y.shape[1] | |
# compute traditional cross entropy cost | |
cross_entropy_cost = compute_cost(AL, y) | |
# convert parameters dictionary to vector | |
parameters_vector = dictionary_to_vector(parameters) | |
# compute the regularization penalty | |
L2_regularization_penalty = ( | |
lambd / (2 * m)) * np.sum(np.square(parameters_vector)) | |
# compute the total cost | |
cost = cross_entropy_cost + L2_regularization_penalty | |
return cost |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment