Solving the problem with logistic regression

While solving this problem with logistic regression i got the following error " RuntimeWarning: overflow encountered in exp"

Here is the link to code:

https://drive.google.com/file/d/1l1DRRHIQwTOqA1485-o0A8T3ZkksuWUP/view?usp=sharing

Hey @Varunsh_20

Try 2 things:

Replace this line:
err = Y*np.log2(h) + (1-Y)*np.log2(1-h)
with:
err = Y*np.log2(h + 1e-8) + (1-Y)*np.log2(1-h + 1e-8)
and scale your data before training the model.

Let me know if this resolves the issue!

Also, never ignore these errors/warnings:

<ipython-input-56-2f333644f022>:2: RuntimeWarning: overflow encountered in exp
  return (1.0/(1.0+np.exp(-1.0*n)))
<ipython-input-56-2f333644f022>:11: RuntimeWarning: divide by zero encountered in log2
  err = Y*np.log2(h) + (1-Y)*np.log2(1-h)
<ipython-input-56-2f333644f022>:11: RuntimeWarning: invalid value encountered in multiply
  err = Y*np.log2(h) + (1-Y)*np.log2(1-h)

log() is not defined / negative infinity at 0 which resulted in this error.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.