Created
November 27, 2018 12:35
-
-
Save ayush1999/8902d81df926a679f91df23006447cf2 to your computer and use it in GitHub Desktop.
trying out linear regression from scratch
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
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