INNER CODE UNIT · Python

compute_cost

amanchadha/coursera-deep-learning-specialization · C2 - Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization/Week 2/opt_utils.py:82

def compute_cost(a3, Y):
    
    """
    Implement the cost function
    
    Arguments:
    a3 -- post-activation, output of forward propagation
    Y -- "true" labels vector, same shape as a3
    
    Returns:
    cost - value of the cost function
    """
    m = Y.shape[1]
    
    logprobs = np.multiply(-np.log(a3),Y) + np.multiply(-np.log(1 - a3), 1 - Y)
    cost = 1./m * np.sum(logprobs)
    
    return cost

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…