Linear Regression step by step for newcomers

Hello. I’m very new to machine and even newer to Julia, as a whole, thought the syntax is still easy to understand. I got a task to train linear regression a set of data (X, y), in which X is the matrix of input vectors, and y is the vector of outputs. The result should be the vector of parameters of linear regression after training (w). What would be the steps for this?

There are multiple methods to do linear regression, the most (statistically) efficient one is ordinary least squares (short OLS; analytically minimizing the sum of squared errors). You can obtain the OLS estimate using just


There also are registered packages you can use, e.g., GitHub - st--/LinearRegression.jl: Simple & fast linear regression in Julia.

1 Like
using GLM
data = DataFrame(your_data_here)
lm(@formula(output ~ input1 + input2 + ...), data)
1 Like

I have researched about that package too, but sadly my assignment is having to make the computer learn itself, which would be through MSE and likely gradient descent.

Is this a homework problem? If so make sure to mention this so people can consider academic integrity issues in responding.

That said you seem to be in luck either way because the link @mcreel posted gives you a worked example of fitting a linear regression in Flux.

This sounds like homework to me, but with all the information out there, the Flux documentation seems like a fair source to use.

1 Like