您的位置:首页 > 其它

【机器学习】数据预处理

2017-01-24 00:06 417 查看
一、回归算法预处理FeatureNormalize

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.

X_norm = X;
mu = zeros(1, size(X, 2));
sigma = zeros(1, size(X, 2));

%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.

for i=1:size(X,2),
mu(i)=mean(X(:,i));
sigma(i)=std(X(:,i));
for j=1:size(X,1),
X_norm(j,i)=(X(j,i)-mu(i))/sigma(i);
end
end

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息