Last active
December 27, 2015 18:09
-
-
Save bahostetterlewis/7367048 to your computer and use it in GitHub Desktop.
AI Question 2 multivariat regression CSCI 580
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beautifully simple and elegant!