📄 aligncenterdata.m.svn-base
字号:
function Xc = alignCenterData(X, y)
%Centers a matrix by taking the alignment mean of each column (feature) of M and
%subtracting the mean from feature value.
%
%inputs
% X is the matrix to be centered
%
%outputs
% Xc is the centered matrix
if (nargin ~= 2)
disp('Usage: alignCenterData(X, y)');
Xc = 0;
return;
end
num_features = size(X, 2);
num_examples = size(X, 1);
Xc = zeros(size(X));
%mean of the positive and negative examples
meanPos = zeros(1, num_features);
meanNeg = zeros(1, num_features);
%Number of positive and negative examples
numPos = 0;
numNeg = 0;
for j=1:num_examples
if y(j) == 1
meanPos = meanPos + X(j, :);
numPos = numPos+1;
else
meanNeg = meanNeg + X(j, :);
numNeg = numNeg+1;
end
end
meanPos = meanPos/numPos;
meanNeg = meanNeg/numNeg;
Xc = X - 0.5*ones(num_examples, 1)*(meanPos + meanNeg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -