This is a continuation of Deep Learning from Zero (Forward Propagation).
Last time, we implemented forward propagation to derive the probability $ AL $ that the input value is $ 1 $. This time, in order to improve the accuracy of the model, we will implement up to the point where the error between the predicted value and the correct label is derived.
Since this DNN predicts whether the input image is a cat or not, we use the Cross-entropy error for the cost function.
It is expressed by the following formula. $ AL $ is a prediction of the probability that Y is 1, and $ Y $ is the correct label.
Returns $ -log (AL) $ when $ Y = 1 $ and $ log (1-AL) $ when $ Y = 0 $. From the graph below, you can see that the farther the predicted value and the correct answer are, the higher the cost.
The function is as follows.
def compute_cost(AL, Y):
m = Y.shape[1]
logprobs = np.multiply(Y, np.log(AL)) + np.multiply(1-Y, np.log(1-AL))
cost = -1/m * np.sum(logprobs)
return cost
Returns the cost by passing the vectorized predicted value $ AL $ and the correct label $ Y $.
Recommended Posts