Skip to content

Instantly share code, notes, and snippets.

@dtellogaete
Last active February 13, 2020 15:44
Show Gist options
  • Save dtellogaete/7a34c021f15f78cf0ff7cc34aa368602 to your computer and use it in GitHub Desktop.
Save dtellogaete/7a34c021f15f78cf0ff7cc34aa368602 to your computer and use it in GitHub Desktop.
# Función de Descenso de Gradiente
LinearRegressionGD = function(lrate = 0.1, niter = 10000,
X, y, theta){
const = lrate*(1/length(X))
for(i in 1:niter){
h = X*theta[2]+theta[1]
theta[1] = theta[1]-const*(sum(h-y))
theta[2] = theta[2]-const*(sum(h-y))*X
}
return(theta)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment