How to handle constant term in Least Squares Regression?

841 Views Asked by At

In the well known matrix form of a least squares regression

where I am trying to solve for B in Y = B1X1 + B2X2 + B3

I might be given X and Y sample data as something like

$X$ = $\begin{bmatrix} 1 & 2 \\ 2 & 3 \\ \end{bmatrix}$

$Y$ = $\begin{bmatrix} 7 \\ 8 \\ \end{bmatrix}$

In such an arrangement how do I include B3? I would think I would want to add it in as always 1 in X

IE

$X$ = $\begin{bmatrix} 1 & 2 \\ 2 & 3 \\ 1 & 1 \\ \end{bmatrix}$

Sorry if the question is not clear.

1

There are 1 best solutions below

1
On BEST ANSWER

Usually the sample data is represented as a 'design matrix' $X$ in which each row represents one training vector. For your $X$ it would look like this:

$\begin{bmatrix} 1 & 2 & 1\\ 2 & 3 & 1\\ \end{bmatrix}$

In general, you need to insert column of $1$'s as the first (or last) column in you design matrix.

The $X$ you proposed would be correct if each column, not row, represented a training example.