I am getting this error. Can someone help me to solve this error:
AttributeError Traceback (most recent call last)
AttributeError: 'NoneType' object has no attribute 'log'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-16-03cf85aa5c36> in <module>
8
9 # Apply gradient descent
---> 10 tmp_J, tmp_theta = gradientDescent(tmp_X, tmp_Y, np.zeros((3, 1)), 1e-8, 700)
11 print(f"The cost after training is {tmp_J:.8f}.")
12 print(f"The resulting vector of weights is {[round(t, 8) for t in np.squeeze(tmp_theta)]}")
<ipython-input-15-66d818b00f54> in gradientDescent(x, y, theta, alpha, num_iters)
26 # calculate the cost function
27 #J = (-1/m)*(np.dot(y.transpose(),np.log(h)) + np.dot((1 - y).transpose(),np.log(1 - h)))
---> 28 J = -(1/m)*np.sum(y*np.log(h)+(1-y)*np.log(1-h))
29
30 # update the weights theta
TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable log method
It looks like either you have not run the “import” cell that imports numpy as np or you have assigned “None” to the variable np someplace in your code.
Please try:
Kernel → Restart and Clear Output
Cell → Run All
and see if that fixes the problem. Or do “Cell → Run All Above” and then rerun that test.
One other theory is that, since the np.dot call earlier in the function did not “throw”, that there is some invisible special character that you typed in the np.log in the J line, so it’s not really the variable np, but somehow still looks like it. The other thing to try would be typing that line over again carefully.
Thank you so much for your reply Paul.
Until this cell, the everything is working fine and as it is. I did not change anything. It throwing an error in the line I created for calculating the cost function.
I did “restarted & clear outputs” and “restart and run all” so many times. And also I did Cell → Run all above. But still I could not solve it. I retyped the line again. But it didn’t help me to solve.
Now, this is the second day, I am struggling to solve this.
The problem is that your sigmoid function fails the tests in the notebook. It looks like you did not implement it, which is where the NoneType error is coming from.