import numpy as np
import matplotlib.pyplot as plt
import math
import random
theta0=random.random()
theta1=random.random()
theta2=random.random()
a=0.01
x=np.array([[2104,3],
[1600,3],
[2400,3],
[1416,2],
[3000,4]])
t=np.array([[400],
[330],
[369],
[232],
[540]])
eps=1e-4
d0=9
d1=9
d2=9
while d0>=eps or d1>=eps or d2>=eps:
b=random.randint(0,4)
i=b
d0=(theta0+theta1*x[i,0]+theta2*x[i,1]-t[i])
d1=(theta0+theta1*x[i,0]+theta2*x[i,1]-t[i])*x[i,0]
d2=(theta0+theta1*x[i,0]+theta2*x[i,1]-t[i])*x[i,1]
theta0=theta0-a*d0
theta1=theta1-a*d1
theta2=theta2-a*d2
print(theta0,theta1,theta2)
[-4.87220222] [-8491.98294871] [-15.35028096]
[135870.66420761] [2.17392366e+08] [407611.25894852]