How to achieve zero mean and unit variance
Mostra commenti meno recenti
I have a matrix 50x3000. How do I achieve zero mean and unit variance
Also How would i normalize the same after applying zero mean and unit variance?
3 Commenti
Image Analyst
il 13 Apr 2014
After you normalize to 0 mean and 1 var, why are you normalizing again? Why not go to your target values all in one operation? Why "normalize" twice? What's the mean and variance the second time?
syd
il 13 Apr 2014
Image Analyst
il 13 Apr 2014
You do it on the shifted version of X. Subtracting the mean merely shifts X without narrowing its distribution. So then you divide to narrow or widen the distribution (X) without shifting it (because it's already shifted).
Risposte (2)
Nils
il 27 Nov 2015
3 voti
You can use the zscore function to zero mean / unit variance any array of data.
For a given matrix A,
A = reshape(zscore(A(:)),size(A,1),size(A,2));
will return the matrix A where all elements now follow a zero mean / unit variance distribution.
It is important to linearize A as the input to zscore, then reshape the output, because zscore will operate differently if you feed it an N-D array rather than a vector.
4 Commenti
sahana kp
il 27 Gen 2017
@Nils when i'm using this code(A = reshape(zscore(A(:)),size(A,1),size(A,2));) got an answer like this >> mean(cA3)
ans =
1.0e-15 *
-0.2722 -0.2722 -0.2722 -0.2722 -0.2722 -0.2722
>> var(cA3)
ans =
1.0278 1.0278 1.0278 1.0278 1.0278 1.0278
is this correct?
Walter Roberson
il 27 Gen 2017
1.0e-15 times those values is probably zero to within numeric round-off, depending on the range of the original values.
If you were to use
format long g
then you would see a less confusing output.
sahana kp
il 30 Gen 2017
@Walter Roberson Now getting the answer like this >> mean(cA3)
ans =
Columns 1 through 5
-2.72183709262942e-16 -2.72183709262942e-16 -2.72183709262942e-16 -2.72183709262942e-16 -2.72183709262942e-16
Column 6
-2.72183709262942e-16
>> var(cA3)
ans =
Columns 1 through 5
1.02777777777778 1.02777777777778 1.02777777777778 1.02777777777778 1.02777777777778
Column 6
1.02777777777778
is this nomalized ?
Walter Roberson
il 30 Gen 2017
Might be normalized. The 1e-16 means are round off error that are impossible to avoid in floating point
Walter Roberson
il 13 Apr 2014
0 voti
3 Commenti
syd
il 13 Apr 2014
Image Analyst
il 13 Apr 2014
Of course some X will be negative. I'd say about half of them will be . Why are you expecting something else ?
John D'Errico
il 27 Nov 2015
How would you have a mean of zero (and a non-zero variance) if some of the elements were not negative?
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!