Log-likelihood (cross-entropy) function

Defined as:

L=1NiN[yiln(s(axi+b))+(1yi)ln(1s(axi+b))]

Used as the Loss function for Logistic function

When p(xi) is close to the ground truth value yi, both loss function terms will have values close to zero, and will produce larger non-zero negative values when p(xi) is different from yi

Given that it will produce a negative value with greater difference, we would like to maximise it (hence bringing it closer to zero). But as good practice, since we prefer to minimise loss functions, we will multiply the loss function by -1

a,b=argmina,b[1NiN[yiln(s(axi+b))+(1yi)ln(1s(axi+b))]]
def log_likelihood_loss(a, b, x, y):
	pred = logistic_regression(x, a, b)
	return -1 * np.mean(y * n.log(pred) + (1-y) * np.log(1 - pred)