Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I am at a point where I stumbled upon something I don't fully understand.

I have to compute the covariance matrix using this formula:

$$\Sigma=\frac{1}{m}\sum_{i=1}^{m}(x^{(i)}-\mu_{y^{(i)}})(x^{(i)}-\mu_{y^{(i)}})^{T}$$

with $$\mu_0=\frac{\sum_{i=1}^{m}1\{y^{(i)}=0\}x^{(i)}}{\sum_{i=1}^{m}1\{y^{(i)}=0\}}$$ and $$\mu_1=\frac{\sum_{i=1}^{m}1\{y^{(i)}=1\}x^{(i)}}{\sum_{i=1}^{m}1\{y^{(i)}=1\}}.$$

My question, $\Sigma$ is a matrix right? $\mu_0$ and $\mu_1$ are also matrices. And here comes what I don't get. $x^{(i)}$ is a training example, let's say with 2 features, say width and height. $\Sigma$ should be a square matrix.

share|improve this question
4  
$\mu_0$ and $\mu_1$ are column vectors or $n\times 1$ matrices if you will. So the product that you are computing is the product of a $n\times 1$ matrix and a $1\times n$ matrix and is thus a $n\times n$ matrix. – Dilip Sarwate Jan 1 '12 at 16:47

1 Answer

up vote 2 down vote accepted

Yes, $\sum$ is definitely a square matrix.

$x^{(i)}$ is indeed the ith data point, and if it has 2 features in it we can consider it a $2 \times 1$ vector. Likewise, if we look at the formulas for $\mu$, we can see that $\sum 1\{y^{(i)} = 0\}x^{(i)}$ is the sum of a bunch of $2 \times 1$ vectors, so the $\mu$'s are also $2 \times 1$ vectors. Now, $\sum$ is the sum of the product of a $2 \times 1$ vector and a $1 \times 2$ vector, so $\sum$ is $2 \times 2$

share|improve this answer

Your Answer

 
discard

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.