MATLAB: How to apply z-score

featuresmachine learningnormalizationstandardizationz-score

Hello
Should I apply z-score (to get zero mean and unit variance) on feature vectors (columns) or data points (rows)? I'm speaking about features in a machine learning context.
Second, how can I do this z-score thing in Matlab?
Thank your very much for the answers beforehand.

Best Answer

You usually work feature by feature.
centered = [A,ones(size(A,1),1)] * [eye(size(A,2));-mean(A)]);
s_and_c = centered * diag(1./std(centered));
(That took entirely too long to work out in terms of matrix algebra! Perhaps this time I will be able to remember for future ;-))