Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

Sorry if the question is not clear.

share|cite|improve this question
up vote 3 down vote accepted

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.

share|cite|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.