My error_list is showing the values " Nan "
Here is my error function:
def error(X,Y,theta):
err = 0.0
m = X.shape[0]
for i in range(m):
hx = hypothesis(X[i],theta)
try:
err += Y[i]*(np.log2(float(hx))) + (1-Y[i])*(np.log2(float(1.0-hx)))
except:
err += 10
return -err
Here’s the hypothesis function :
def hypothesis(x,theta):
z = np.dot(x,theta)
return sigmoid(z)
def sigmoid(z):
gz = 1.0/(1.0 + np.exp(-1.0*z))
return gz
I added try and except block because it was giving an exception :
RuntimeWarning: divide by zero encountered in log2
RuntimeWarning: invalid value encountered in double_scalars
WHAT TO DO ??