import numpy as np
import math
import random
x1= np.array([2104,1600,2400,1416,3000])
x2 = np.array([3,3,3,2,4])
t = np.array([400,330,369,232,540])
theta0=random.random()
theta1=random.random()
theta2=random.random()
alpla = 0.1
e = 0.0000001
k0=random.random()
k1=random.random()
k2=random.random()
i=0
while (k0>=e or k1>=e or k2>=e):
k0=x2[i]*theta2+x1[i]*theta1+theta0-t[i]
k1=k0*x1[i]
k2=k0*x2[i]
theta0=theta0-alpla*k0
theta1=theta1-alpla*k1
theta2=theta2-alpla*k2
i=i+1
print(k0,k1,k2)
print(theta0,theta1,theta2)
-415873024.14696944 -665396838635.1511 -1247619072.4409084
41587179.24212728 66539423943.85159 124761537.46500464
|