This function calculates the difference between the output you have obtained and the y that should be.
Python Code of Loss Function
import numpy as np def custom_loss(y, yhat): return -(y*np.log(yhat) - (1-y)*np.log(1-yhat)**2).mean()
The cost function is the average of the error function. We will find the w and b parameters that minimize the total cost.
Python Code of Cost Function
import numpy as np def cost_func(Y,Yhat,m): return -1/m * np.sum(np.dot(Y,np.log(Yhat)) + np.dot(1-Y, np.log(1-Yhat)))