Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorization of featureNormalization #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function [X_norm, mu, sigma] = featureNormalize(X)
function [x_norm, mu, sigma] = featureNormalize(x)
%FEATURENORMALIZE Normalizes the features in X
% FEATURENORMALIZE(X) returns a normalized version of X where
% the mean value of each feature is 0 and the standard deviation
% is 1. This is often a good preprocessing step to do when
% working with learning algorithms.

% You need to set these values correctly
X_norm = X;
mu = zeros(1, size(X, 2));
sigma = zeros(1, size(X, 2));
x_norm=x;

%x_norm(:,2) = (x(:,2)-mu(:,2))/sigma(:,2);
%x_norm(:,1) = (x(:,1)-mu(:,1))/sigma(:,1);
% ====================== YOUR CODE HERE ======================
% Instructions: First, for each feature dimension, compute the mean
% of the feature and subtract it from the dataset,
Expand All @@ -26,21 +26,16 @@
% Hint: You might find the 'mean' and 'std' functions useful.
%

n = size(X, 2);

for i = 1:n
mu = mean(x);
sigma = std(x);
x_norm =(x.- mean(x,1))./std(x,0,1);


avg = mean(X(:, i));
deviation = std(X(:, i));

X_norm(:, i) = X_norm(:, i) - avg;
X_norm(:, i) = X_norm(:, i) / deviation;

mu(i) = avg;
sigma(i) = deviation;

end

% ============================================================

end
end