costFunction

import numpy as np

import matplotlib

import math

x1 = np.array([[2104,3],[1600,3],[2400,3],[1416,2]])

x2 = np.array([3,3,3,2])

t = np.array([400,330,369,232])

alpha = 0.01

th0 = np.random.random()

th1 = np.random.random()

th2 = np.random.random()

th = np.array([th1,th2])




''''''

eps = 1e-4
e0 = 9
e1 = 9
e2 = 9

''''''
while e0 >= eps or e1 >= eps or e2 >= eps:

    i = 0

    e0 = np.sum((x1[:, i] * th1[i]) + th0 * 1 - t[i])

    e1 = e0 * x1[i, 0]

    e2 = e1 * x1[i, 1]

    th0 = th0 - alpha * e0

    th1 = th1 - alpha * e1

    th2 = th2 - alpha * e2

    i += 1

    print(th0, th1, th2)

costFunction

上一篇:定时器计数器T1典例


下一篇:【线性代数】正交向量和正交子空间