MySQL is perfectly capable of calculating a linear regression for you, btw. In my case, I needed to be able to estimate trends from sparse time series data. Here's how you do that: SELECT @a_count := avg(count) as mean_count, @a_weeks := avg(`week`) as mean_weeks, @covariance := (sum(`week` * `count`) - sum(`week`) * sum(`count`) / count(`week`)) / count(`week`) as covariance, @stddev_count := stddev(`count`) as stdd…
Linear regression by hand
21–30 of 36 posts
Re: Linear regression by hand
#22Can someone explain to me why this has (so many) upvotes? This is like elementary undergraduate econ stats and kind of trivial? There's very little content either, it's literally a reformulation of the formula, no interesting graphs or geometric interpretation. What I expected from a title like "Linear Regression By Hand" was the minimization of some quadratic error function, by hand (i.e. using pencil and paper).
https://www.xkcd.com/1053/ I almost certainly know something I'd consider "trivial" that you haven't encountered yet. I try to be really excited when that happens.
Re: Linear regression by hand
#23Can someone explain to me why this has (so many) upvotes? This is like elementary undergraduate econ stats and kind of trivial? There's very little content either, it's literally a reformulation of the formula, no interesting graphs or geometric interpretation. What I expected from a title like "Linear Regression By Hand" was the minimization of some quadratic error function, by hand (i.e. using pencil and paper).
Re: Linear regression by hand
#24It's way more fun to know how to derive least squares than to memorize some formula: https://see.stanford.edu/materials/lsoeldsee263/05-ls.pdf (page 4)
Re: Linear regression by hand
#25Can someone explain to me why this has (so many) upvotes? This is like elementary undergraduate econ stats and kind of trivial? There's very little content either, it's literally a reformulation of the formula, no interesting graphs or geometric interpretation. What I expected from a title like "Linear Regression By Hand" was the minimization of some quadratic error function, by hand (i.e. using pencil and paper).
Re: Linear regression by hand
#26Re: Linear regression by hand
#27MySQL is perfectly capable of calculating a linear regression for you, btw. In my case, I needed to be able to estimate trends from sparse time series data. Here's how you do that: SELECT @a_count := avg(count) as mean_count, @a_weeks := avg(`week`) as mean_weeks, @covariance := (sum(`week` * `count`) - sum(`week`) * sum(`count`) / count(`week`)) / count(`week`) as covariance, @stddev_count := stddev(`count`) as stdd…
Yes, but why ? Right tool for the right job and all that...
I share your doubt that this is worth it, to be clear.
Re: Linear regression by hand
#28MySQL is perfectly capable of calculating a linear regression for you, btw. In my case, I needed to be able to estimate trends from sparse time series data. Here's how you do that: SELECT @a_count := avg(count) as mean_count, @a_weeks := avg(`week`) as mean_weeks, @covariance := (sum(`week` * `count`) - sum(`week`) * sum(`count`) / count(`week`)) / count(`week`) as covariance, @stddev_count := stddev(`count`) as stdd…
Yes, but why ? Right tool for the right job and all that...
The latter might be conceptually cleaner (though it's debatable, relational is a fairly nice programming model and a lot more consistent and well-founded than object orientation, for one), but it's seldom optimal.
Three orders of magnitude or more speedups are not unexpected by pushing the code to the data.
Re: Linear regression by hand
#29This is very dangerous and an awful way to compute the least squares fit due to potential numerical issues with calculating the inverse of the matrix. I wish he would put a warning in a huge bold header to never do this for actual production work .
Re: Linear regression by hand
#30Earlier quoted context omitted.
Yes, but why ? Right tool for the right job and all that...
I would guess access to the data is a decent reason to try. No need to pump the data elsewhere, if this is available. I share your doubt that this is worth it, to be clear.
And besides, what happened to the hacker ethos? "Because I can" should be justification enough. :-)