Normalize features
This commit is contained in:
parent
613220bb3e
commit
8559c243c5
1 changed files with 10 additions and 1 deletions
|
@ -26,9 +26,18 @@ sigma = zeros(1, size(X, 2));
|
||||||
% Hint: You might find the 'mean' and 'std' functions useful.
|
% Hint: You might find the 'mean' and 'std' functions useful.
|
||||||
%
|
%
|
||||||
|
|
||||||
|
mu = mean(X);
|
||||||
|
sigma = std(X);
|
||||||
|
|
||||||
|
% This gives broadcasting warnings, but works, too:
|
||||||
|
%
|
||||||
|
% X_norm = (X - mu) ./ sigma;
|
||||||
|
%
|
||||||
|
% warning: operator -: automatic broadcasting operation applied
|
||||||
|
% warning: quotient: automatic broadcasting operation applied
|
||||||
|
|
||||||
|
|
||||||
|
X_norm = bsxfun(@rdivide, bsxfun(@minus, X, mu), sigma);
|
||||||
|
|
||||||
% ============================================================
|
% ============================================================
|
||||||
|
|
||||||
|
|
Reference in a new issue