My Code (from coursera):
def gradient_desc(X, Y, w_in, b_in, cost_f, grad_f, alp, num, lambda_):
m = len(X)
# An array to store cost J and w's at each iteration primarily for graphing later
J_history = []
w_history = []
for i in range(num):
# Calculate the gradient and update the parameters
dj_db, dj_dw = grad_f(X, Y, w_in, b_in, lambda_)
# Update Parameters using w, b, alpha and gradient
w_in = w_in - alpha * dj_dw
b_in = b_in - alpha * dj_db
# Save cost J at each iteration
if i<100000: # prevent resource exhaustion
J_history.append(cost_f(X, Y, w_in, b_in, lambda_))
# Print cost every at intervals 10 times or as many iterations if < 10
if i% math.ceil(num/10) == 0:
w_history.append(w_in)
print(f"Iteration {i:4}: Cost {float(J_history[-1]):0.2e} ")
return w_in, b_in, J_history, w_history #return w and J,w history for graphing
The error:
TypeError: float() argument must be a string or a real number, not 'NoneType'
This is the only bit in the entire code that is bugging (at least bugging till now). How to resolve this?