I am writing some code that uses a Least-Squares estimator. Of course, as mentioned HERE, the covariance matrix can be obtained from $\sigma^2(X'X)^{-1}$.
The problem I have, is that I have no idea how to get the constant factor. As the number of measurements goes up, the covariance seems to converge to the correct value, but of course, you never have infinite measurements.
So, how do I find the $\sigma^2$? I read that you can use the residual to estimate it, but I don't see the relationship.