feature normalization

I was doing Coursera—machine learning(Andrew Ng)第二周编程作业 reading this线性回归–Octave实现Coursera机器学习-Week 2-编程作业:Linear RegressionCoursera—machine learning(Andrew Ng)第二周编程作业I don’t really get thissigma = std(X, 1, 1);despite it says …still don’t get it >> help std’std’ is a function from the file E:\Octave\Octave-4.4.1\share\octave\4.4.1\m\statistics\std.m – std (X) – std (X, OPT) – std (X, OPT, DIM) Compute the standard deviation of the elements of the vector X. The standard deviation is defined as std (X) = sqrt ( 1/(N-1) SUM_i (X(i) - mean(X))^2 ) where N is the number of elements of the X vector. If X is a matrix, compute the standard deviation for each column and return them in a row vector. The argument OPT determines the type of normalization to use. Valid values are 0: normalize with N-1, provides the square root of the best unbiased estimator of the variance [default] 1: normalize with N, this provides the square root of the second moment around the mean If the optional argument DIM is given, operate along this dimension. See also: var, bounds, mad, range, iqr, mean, median.Additional help for built-in functions and operators isavailable in the online version of the manual. Use the command’doc <topic>’ to search the manual index.But it seems the code can be simple like this..I don’t know whether I am right here though..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 correctlyX_norm = X;mu = zeros(1, size(X, 2));sigma = zeros(1, size(X, 2));% ====================== YOUR CODE HERE ======================% 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. %% Hint: You might find the ‘mean’ and ‘std’ functions useful.% mu = mean(X);sigma = std(X);disp(‘mu’),disp(mu);disp(‘sigma’),disp(sigma);sigma= std(X);X_norm = (X-mu) ./ sigma; disp(‘X_norm’),disp(X_norm);% ============================================================end ...

February 11, 2019 · 2 min · jiezi

Octave 入门

Matlab实在太贵,所以Andrew Ng推荐的完全开源免费的Octave却是个好的替代物。关于为什么要用Octave,而不是用别的Matlab代替品如Freemat, Spider等,这篇AskUbuntu里有非常详尽的解答。简而言之:Octave是Matlab毫无疑问的最好代替品,语法相似性达95%以上,功能完善,且社区、文档非常详尽。反之其它代替品,则要不就语法相似度低、要不就功能不全、要不就几乎没有文档学习参考。Octave 安装 (命令行中运行)安装GNU官网的说明,参考自己的平台安装方式。Mac上直接brew install octave即可。可以看到,octave需要非常多的依赖包。我装了大概一个多小时吧。完成后,就可以通过命令行输入octave直接进入了:Octave 安装 (包括GUI界面)参考官网页面。Mac版的GUI版Ocatave下载地址,下载好后是大概300M的dmg文件。然后打开后,完成初始提示,就可以看到主页面了:Octave 安装(Jupyter notebook)在本机已安装Octave、Jupyter的情况下,进入Jupyter notebook的运行环境(系统或虚拟环境),输入这些命令安装:pip install metakernelpip install octave_kernelpython -m octave_kernel installecho export OCTAVE_EXECUTABLE=$(which octave) >> ~/.zshrc然后重启Jupyter就可以看到多了一个Octave kernel了。Octave绘图命令行中的Octave也是能绘图的,只要用plot(…)函数就行。它会弹出一个小窗口,显示图形。效果如下:关于Mac上Octave GUI客户端运行缓慢问题需要注意的一点是,Mac上的Octave极其缓慢,程序经常自动停止运转,一个一根线的绘图更是要等很久。所以没有耐心的又想用Octave的,还是在命令行里用吧。

January 23, 2019 · 1 min · jiezi