# Confused about within-class scatter matrix in linear discriminant analysis

I am trying to implement Linear Discriminant Analysis. I have 10 classes and each class has 3 observations at various instances:

class 1 = {{a1,a2,a3}
{b1,b2,b3}
{c1,c2,c3}}


a,b,c are 3 observations found at various instances a1,a2,a3. Class 1 is a 3*3 Matrix!

Now I have to find the mean observation of each class. For example, I have to find the mean of class 1:

A = (a1+a2+a3)/3
B = (b1+b2+b3)/3
C = (c1+c2+c3)/3
mean of class1 = (A+B+C)/3


I am confused at this point, kindly help me to solve this?

Clarification update: I am trying to implement image recognition using LDA, my class1 matrix is of size 10*32256 of 10 sample images. Like this I have 5 classes. I was confused how to take mean for this matrix: whether to add all the instance of row 1 and divide by 32256 or add the column and divide by 10.

• Is your question about statistics or about programming in Java? Commented Mar 31, 2014 at 3:16
• sorry,its about statistics Commented Mar 31, 2014 at 3:17
• In your case, instances are the variables of the analysis. So, you should logically compute means within instances, not within observations. But it is questionnable if "instances" can be seen as features. Features exist simultaneously. Do your 3 instances exist simultaneously? Commented Mar 31, 2014 at 5:57
• I am trying to implement image recognition using LDA, my class1 matrix is of size 10*32256 of 10 sample images.like this i have 5 classes. I was confused how to take mean for this matrix. whether to add all the instance of row 1 and divide by 32256 or add the column and divide by 10. Commented Mar 31, 2014 at 8:21

You are using a confusing terminology. Alotugh there are several way to express the same concept, note that one observation is one instance. One instance can have multiple characteristics/features/columns/variables/... Now for what it concerns computing the average of classes, the mathematical formula would be:

\begin{equation*} \mu_i = \frac{1}{N_i} \sum_{x \in \omega_i} x \end{equation*}

for the class average and for the global average:

\begin{equation*} \mu = \frac{1}{n} \sum_{i=1}^n x_i = \frac{1}{n} \sum_{i=1}^C N_i \mu_i \end{equation*}

Where $\omega_i$ denotes a class label, $N_i$ are the class sizes and $n$ the total number of samples. In your JAVA related situation, if you have 10 classes but only 3 instances per class, expect poor results. Anyway, class average for class 1 would be computed as (if your columns are the features and the rows the observations) as:

avg = [(a1+b1+c1/3),(a2+b2+c2/3),(a3+b3+c3/3)]


And that would be a three dimensional vector, not a single scalar. As you are working with multi dimensional data you cannot expect that the mean is a single number only.

• +1. Thanks, again, for answering these old questions. Original posters are usually long gone so such answers will probably never get accepted (and rarely attract much attention), but it is nevertheless very useful for the site to have these questions answered. Commented Aug 2, 2016 at 16:56