Linear regression
If you&#x27;re new to learning about regression and want to use it, I would prioritize the statistical issues. There are lots of computational details you could read about, like in this post. However in simple cases, fitting least-squares linear regression is one line of code:<p><pre><code>    w_fit = X \ yy; % Matlab&#x2F;Octave, X is NxD, yy is Nx1
    w_fit = np.linalg.lstsq(X, yy)[0] # NumPy equivalent
</code></pre>
Knowing how to construct the &quot;design matrix&quot; X is the important bit. What are your features, how will they be pre-processed, and given what you&#x27;ve done, should you trust w_fit to be meaningful, or just useful for prediction?<p>If you&#x27;ve thrown in lots of features, hoping to get good predictions, you may want to do &quot;regularization&quot;. The computation is no harder for simple versions. One way to do &quot;L2 regularization&quot; is to add some extra rows to X and yy before fitting the weights:<p><pre><code>    % Matlab&#x2F;Octave... the NumPy is nearly as simple.
    [N, D] = size(X);
    lambda = 1; % regularization constant
    X = [X; eye(D)*sqrt(lambda)];
    y = [yy; zeros(D,1)]
</code></pre>
Or you could use an actual stats package like R&#x27;s libraries that will contain a lot more care. Again, you need to understand the statistics, for example how you should select lambda. Then you&#x27;ll want to know how to diagnose your model and whether you should trust it.<p>It&#x27;s fun to work out the least squares maths and implement these things from scratch. But it has been done, and it&#x27;s not what matters for most applications.<p>EDIT: a discussion with good links on linear models and beyond from the other day <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12237998" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12237998</a>