Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the BigO of linear regression?

How large a system is it reasonable to attempt to do a linear regression on?

Specifically: I have a system with ~300K sample points and ~1200 linear terms. Is this computationally feasible?

like image 344
BCS Avatar asked Dec 23 '09 20:12

BCS


People also ask

What is the time complexity of linear regression?

Linear Regression Train Time Complexity=O(n*m^2 + m^3) Test Time Complexity=O(m)

What is meant by linear regression?

In statistics, linear regression is a linear approach for modelling the relationship between a scalar response and one or more explanatory variables (also known as dependent and independent variables).

What are types of linear regression?

There are two kinds of Linear Regression Model:- Simple Linear Regression: A linear regression model with one independent and one dependent variable. Multiple Linear Regression: A linear regression model with more than one independent variable and one dependent variable.

What is residual in simple linear regression?

The difference between an observed value of the response variable and the value of the response variable predicted from the regression line.


2 Answers

The linear regression is computed as (X'X)^-1 X'Y.

If X is an (n x k) matrix:

  1. (X' X) takes O(n*k^2) time and produces a (k x k) matrix

  2. The matrix inversion of a (k x k) matrix takes O(k^3) time

  3. (X' Y) takes O(n*k^2) time and produces a (k x k) matrix

  4. The final matrix multiplication of two (k x k) matrices takes O(k^3) time

So the Big-O running time is O(k^2*(n + k)).

See also: http://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Matrix_algebra

If you get fancy it looks like you can get the time down to O(k^2*(n+k^0.376)) with the Coppersmith–Winograd algorithm.

like image 80
Emiller Avatar answered Oct 13 '22 21:10

Emiller


You can express this as a matrix equation:

alt text

where the matrix alt text is 300K rows and 1200 columns, the coefficient vector alt text is 1200x1, and the RHS vector alt text is 1200x1.

If you multiply both sides by the transpose of the matrix alt text, you have a system of equations for the unknowns that's 1200x1200. You can use LU decomposition or any other algorithm you like to solve for the coefficients. (This is what least squares is doing.)

So the Big-O behavior is something like O(mmn), where m = 300K and n = 1200. You'd account for the transpose, the matrix multiplication, the LU decomposition, and the forward-back substitution to get the coefficients.

like image 27
duffymo Avatar answered Oct 13 '22 21:10

duffymo