Does Logistic Regression cost function use log10 or ln?

In the video about Logistic Regression Cost Function of week 2, the loss function is presented as:

L(yhat ,y)=-(y log(yhat) + (1-y)log(1-yhat))

I have two questions:

  1. Is the log function the base 10 logarithm or the ln function?
  2. When saying that we want to mimise that function, does that mean that we want to make it, as negative as possible or as close to zero as possible?


Hi, for your questions

  1. Technically speaking it can be any, log or ln, as both would differ by a multiple of 2.303. But in the programming assignments here, we use log.
  2. Let’s say the label is y = 1 and logistic regression model’s output yhat = 1, then the loss value is 0. Whereas, when the label is y=1 and yhat is a very small number close to 0, then the loss value is a very large positive value. Considering these two cases as corner cases, we want to minimize the loss function to as close to zero as possible. (similar explanation when y=0).
1 Like

Thanks, that clarifies.

It is the natural (base e) logarithm. The function for that is np.log(). Common (i.e., base 10) logarithms do not have much appeal anymore since the invention of the digital calculator. Folks used to use slide rules to convert multiplications into sums.

And, welcome to the specialization @m.emmanuel!

1 Like