however my cost is continuously decreasing but my linear regression is unable to predict just simple pattern y=x+5
please suggest something i tried all value for alpha and minimum cost i got is 3.00
x=[]
y=[]
for i in range(1000):
x.append(i)
y.append(i+5)
def compute_cost(x,y,w,b):
m=len(x)
total_cost=0
cost=0
for i in range(m):
f_wb = w*x[i]+b
cost += (f_wb - y[i])**2
total_cost = cost/(2*m)
return total_cost
def gradient_descent(x,y,iter=200):
m=len(x)
w=0
b=0
alpha=0.0000001
for i in range(iter):
dj_dw,dj_db=Compute_gradient(x,y,w,b)
w-=alpha*dj_dw
b-=alpha*dj_db
if(i%10==0):
cost=compute_cost(x,y,w,b)
print(f"cost at iteration {i} is {cost}")
return w,b
def Compute_gradient(x,y,w,b):
m=len(x)
dj_dw=0
dj_db=0
for i in range(m):
y_predict=w*x[i]+b
dj_dw +=(y_predict-y[i])*x[i]
dj_db +=(y_predict-y[i])
dj_dw /=m
dj_db /=m
return dj_dw,dj_db
w,b=gradient_descent(x,y)
q=w*10+b
print(q)
here is output
cost at iteration 0 is 157869.16787934472
cost at iteration 10 is 80221.1618112745
cost at iteration 20 is 40765.111675992295
cost at iteration 30 is 20715.91825636264
cost at iteration 40 is 10528.123091503312
cost at iteration 50 is 5351.297861860537
cost at iteration 60 is 2720.746400189429
cost at iteration 70 is 1384.058239492339
cost at iteration 80 is 704.8336487635617
cost at iteration 90 is 359.6925315439946
cost at iteration 100 is 184.31255755759477
cost at iteration 110 is 95.19499412720666
cost at iteration 120 is 49.910803477032324
cost at iteration 130 is 26.900098542186733
cost at iteration 140 is 15.20744043888423
cost at iteration 150 is 9.265933534732453
cost at iteration 160 is 6.246816032905587
cost at iteration 170 is 4.712681193345336
cost at iteration 180 is 3.93312529712553
cost at iteration 190 is 3.537001070649068
10.064986594681566
please review what is wrong