Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fit(n, m, X, y):
- theta = np.zeros(n+1)
- for iter in range(iterations):
- for i in range(len(X)):
- h = sum([X[i][j] * theta[j] for j in X[i]])
- # konstantny clen
- h += theta[n];
- for tr in X[i]:
- theta[tr] = theta[tr] - alpha * (y[i] - h) * X[i][tr];
- #konstantny clen
- theta[n] = theta[n] - alpha * (y[i] - h);
- train_error = 0
- for i in range(len(X)):
- h = sum([X[i][j] * theta[j] for j in X[i]])
- #konstantny clen
- h=+ theta[n];
- train_error += (h - y[i])**2
- train_error/=(2*m)
- return theta,train_error
- n, m, X, y = load_data(sys.argv[1])
- theta, train_error = fit(n, m, X, y)
- print "Training error", train_error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement