ML coursera提交(第2周)特征规范化

时间:2017-09-21 19:24:13

标签: machine-learning submit normalization

我已经为功能规范化编写了以下代码 这里X是特征矩阵(m * n) 哪里 m =例子的数量 n =要素数量

mu = mean(X);
sigma = std(X);

m = size(X,1);

% Subtracting the mean from each row 
for i = 1:m
    X_norm(i,:) = X(i,:)-mu;
end;

% Dividing the STD from each row 
for i = 1:m
    X_norm(i,:) = X(i,:)./sigma;
end;

但是在将它提交给为Andrew Ng的课程构建的服务器时,如果它的错误或正确,它不会给我任何确认。

==
==                                   Part Name |     Score | Feedback
==                                   --------- |     ----- | --------
==                            Warm-up Exercise |  10 /  10 | Nice work!
==           Computing Cost (for One Variable) |  40 /  40 | Nice work!
==         Gradient Descent (for One Variable) |  50 /  50 | Nice work!
==                       Feature Normalization |   0 /   0 |
==     Computing Cost (for Multiple Variables) |   0 /   0 |
==   Gradient Descent (for Multiple Variables) |   0 /   0 |
==                            Normal Equations |   0 /   0 |
==                                   --------------------------------
==                                             | 100 / 100 |

注意:抱歉如果我违反了课程代码,我们不知道该怎么做。

4 个答案:

答案 0 :(得分:0)

当submit()没有给你任何积分时,这意味着你的答案是不正确的。 这通常意味着,您尚未实现它,或者您的实现中存在错误。

从我所看到的,你的指数不正确。但是,为了不违反本课程的行为准则,您应该在Coursera论坛中提出您的问题(不发布您的代码)。

每个编程练习都有教程。这些通常非常有用,并指导您完成整个练习。

答案 1 :(得分:0)

您需要迭代每个功能

m = size(X,1);

用m实际得到的是ROWS的数量(示例),但是您想获得COLUMNS的数量(功能)

解决方案:

m = size(X,2);

答案 2 :(得分:0)

尝试使用此方法,请注意,将X的每一行都除而不加均值是错误的。

将两者组合在一起,并使用更少的代码-

% Subtracting the mean and Dividing the STD from each row. for i = 1:m X_norm(i,:) = (X(i,:) - mu) ./ sigma; end;

答案 3 :(得分:0)

在课程结束时,最终正确答案为featureNormalize.m

function [X_norm, mu, sigma] = featureNormalize(X)
  %description: 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.
  
  X_norm = X;
  mu = zeros(1, size(X, 2));
  sigma = zeros(1, size(X, 2));
  
  % Instructions: First, for each feature dimension, compute the mean
  %               of the feature and subtract it from the dataset,
  %               storing the mean value in mu. Next, compute the 
  %               standard deviation of each feature and divide
  %               each feature by it's standard deviation, storing
  %               the standard deviation in sigma. 
  %
  %               Note that X is a matrix where each column is a 
  %               feature and each row is an example. You need 
  %               to perform the normalization separately for 
  %               each feature. 
  
  mu = mean(X);
  sigma = std(X);
  X_norm = (X - mu)./sigma;
end

如果您正在上这门课并且有复制和粘贴的冲动,那么您就处于学术诚信的灰色地带。你应该从第一原则中找出答案,而不是谷歌搜索并反驳答案。