Last active
November 13, 2018 17:19
-
-
Save conormm/cc0848c1992fec5ac575da93dfc46a7a to your computer and use it in GitHub Desktop.
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
for (iteration in seq_len(n_iterations)) { | |
yhat <- dot(x_b, theta) # predict using weights in theta | |
residuals_b <- yhat - y # calculate the residuals | |
gradients <- 2/n * dot(t(x_b), residuals_b) # calculate the gradients of MSE w.r.t model weights | |
theta <- theta - learning_rate * gradients # update theta | |
sse_i[[iteration]] <- sum((y - dot(x_b, theta))**2) | |
b0[[iteration]] <- theta[2] | |
b1[[iteration]] <- theta[1] | |
} | |
model_i <- data.frame(model_iter = 1:n_iterations, | |
sse = sse_i, | |
b0 = b0, | |
b1 = b1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment