Skip to content

Instantly share code, notes, and snippets.

@ayush1999
Created November 27, 2018 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayush1999/8902d81df926a679f91df23006447cf2 to your computer and use it in GitHub Desktop.
Save ayush1999/8902d81df926a679f91df23006447cf2 to your computer and use it in GitHub Desktop.
trying out linear regression from scratch
mutable struct LinearRegression
inputs::Any
targets::Any
params::Any
end
function LinearRegression(a::Any, b::Any)
params = zeros(size(a, 2), 1)
err = []
for i=1:size(a, 1)
push!(err, (a*params)[i] - b[i])
println(err[i])
end
for i=1:2000
for j=1:size(a, 2)
params[j] = params[j] - (2*0.01*(transpose(a[:,j])*err)/size(a, 1))[1]
end
err = []
for i=1:size(a, 1)
push!(err, (transpose(a[1,:])*params)[1] - b[i])
end
println("Current loss is $(sum(err.^2))")
end
return LinearRegression(a, b, params)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment