Skip to content

Instantly share code, notes, and snippets.

@bahostetterlewis
Last active December 27, 2015 18:09
Show Gist options
  • Save bahostetterlewis/7367048 to your computer and use it in GitHub Desktop.
Save bahostetterlewis/7367048 to your computer and use it in GitHub Desktop.
AI Question 2 multivariat regression CSCI 580
xs, ys, ws = [None, [1, 1, 2], [1, 2, -1], [1, 5, -2], [1, 3, -1], [1, 8, 2]], [None, -13, -4, 5, 0, 1], [1, 1, 1]
alpha = .01
def h(j):
return (ws[0] * xs[j][0]) + (ws[1] * xs[j][1]) + (ws[2] * xs[j][2])
def inner(inner_i):
return (xs[inner_j][inner_i] * (ys[inner_j] - hs[inner_j]) for inner_j in range(1, len(xs)))
for count in range(100000):
hs = [None] + [h(j) for j in range(1, len(xs))]
ws = [w + alpha * sum(inner(i)) for i, w in enumerate(ws)]
print(hs[1:], '\n', ws)
@nitrohorse
Copy link

Beautifully simple and elegant!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment