# How to handle constant term in Least Squares Regression?

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 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.

-
Thanks Blazej. Later today I will try it out and confirm then I will certainly accept the answer. BTW you are spot on I transposed the training vectors for some reason......Thanks again. – Pablitorun Mar 1 '11 at 22:58