1.Feature Normalization:

归一化的处理

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)); % ====================== 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.
% for i=1:size(X,2),
mu(i)=mean(X(:,i));
sigma(i)=std(X(:,i));
X_norm(:,i)=(X_norm(:,i)-mu(i))/sigma(i);
end; % ============================================================ end

2. Computing Cost (for Multiple Variables) && Gradient Descent (for Multiple Variables)

由于我们单变量的时候就是用矩阵形式处理的,所以代码与单变量相同;

3.Normal Equations

正规方程就比较简单了;

function [theta] = normalEqn(X, y)
%NORMALEQN Computes the closed-form solution to linear regression
% NORMALEQN(X,y) computes the closed-form solution to linear
% regression using the normal equations. theta = zeros(size(X, 2), 1); % ====================== YOUR CODE HERE ======================
% Instructions: Complete the code to compute the closed form solution
% to linear regression and put the result in theta.
% % ---------------------- Sample Solution ---------------------- theta=inv(X'*X)*X'*y; % ------------------------------------------------------------- % ============================================================ end

Machine learning吴恩达第二周coding作业(选做)的更多相关文章

  1. Machine learning 吴恩达第二周coding作业(必做题)

    1.warmUpExercise: function A = warmUpExercise() %WARMUPEXERCISE Example function in octave % A = WAR ...

  2. Machine Learning——吴恩达机器学习笔记(酷

    [1] ML Introduction a. supervised learning & unsupervised learning 监督学习:从给定的训练数据集中学习出一个函数(模型参数), ...

  3. Machine learning吴恩达第三周 Logistic Regression

    1. Sigmoid function function g = sigmoid(z) %SIGMOID Compute sigmoid function % g = SIGMOID(z) compu ...

  4. Deap Learning (吴恩达) 第一章深度学习概论 学习笔记

    Deap Learning(Ng) 学习笔记 author: 相忠良(Zhong-Liang Xiang) start from: Sep. 8st, 2017 1 深度学习概论 打字太麻烦了,索性在 ...

  5. 吴恩达机器学习笔记38-决策下一步做什么(Deciding What to Do Next Revisited)

    我们已经讨论了模型选择问题,偏差和方差的问题.那么这些诊断法则怎样帮助我们判断,哪些方法可能有助于改进学习算法的效果,而哪些可能是徒劳的呢? 让我们再次回到最开始的例子,在那里寻找答案,这就是我们之前 ...

  6. Github | 吴恩达新书《Machine Learning Yearning》完整中文版开源

    最近开源了周志华老师的西瓜书<机器学习>纯手推笔记: 博士笔记 | 周志华<机器学习>手推笔记第一章思维导图 [博士笔记 | 周志华<机器学习>手推笔记第二章&qu ...

  7. 我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)【中英双语】

    我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)[中英双语] 视频地址:https://www.bilibili.com/video/av9912938/ t ...

  8. 【吴恩达课后编程作业】第二周作业 - Logistic回归-识别猫的图片

    1.问题描述 有209张图片作为训练集,50张图片作为测试集,图片中有的是猫的图片,有的不是.每张图片的像素大小为64*64 吴恩达并没有把原始的图片提供给我们 而是把这两个图片集转换成两个.h5文件 ...

  9. 【吴恩达课后测验】Course 1 - 神经网络和深度学习 - 第二周测验【中英】

    [中英][吴恩达课后测验]Course 1 - 神经网络和深度学习 - 第二周测验 第2周测验 - 神经网络基础 神经元节点计算什么? [ ]神经元节点先计算激活函数,再计算线性函数(z = Wx + ...

随机推荐

  1. [C++] Memory Retrieval(内存检索)

    Traverse the memory by  (char*) , because every time it will increase by 1byte when i want get the i ...

  2. Red Hat 6.5 Samba服务器的搭建(匿名访问,免登录)

    搭建Samba服务器是为了实现Linux共享目录之后,在Windows可以直接访问该共享目录. 现在介绍如何在红帽6.5系统中搭建Samba服务. 搭建Samba服务之前,yum源必须配置好,本地源和 ...

  3. linux tomcat自动部署shell

    #!/bin/bash   #defined    TOMCAT_HOME="/usr/java/tomcat/tomcat"   TOMCAT_PORT=80   PROJECT ...

  4. Hadoop(HDFS、YARN、HBase、Hive和Spark等)默认端口表

    端口 作用 9000 fs.defaultFS,如:hdfs://172.25.40.171:9000 9001 dfs.namenode.rpc-address,DataNode会连接这个端口 50 ...

  5. Memcache+Cookie替代Session解决方案(MVC版)

    阅读目录 开始 通过IHttpModule注册过滤管道方式 通过BaseController 关于滑动过期 两种方式 回到顶部 通过IHttpModule注册过滤管道方式 具体实现如下: 声明一个类C ...

  6. apache mina2.0源码解析(一)

    apache mina是一个基于java nio的网络通信框架,为TCP UDP ARP等协议提供了一致的编程模型:其源码结构展示了优秀的设计案例,可以为我们的编程事业提供参考. 依照惯例,首先搭建a ...

  7. CF869C The Intriguing Obsession(组合数学瞎搞,O(n)莫名过)

    — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...

  8. 第一课 了解SQL

    1.1数据库基础 数据库:数据库是一个以某种有组织的方式存储的数据集合,可以想象是一个文件柜 数据库管理软件:DBMS用来操做创建数据库的软件 表:某种特定类型数据的结构化清单,数据库的下一层就是表 ...

  9. C++ 动态分配二维和三维数组

    目的:熟悉c++动态内存分配 描述:使用c++程序定义动态数组类,使用new和delete操作符实现动态二维数组和三维数组的定义 //main.cpp //主程序类 #include <iost ...

  10. 所有中心对称五字母域名生成,扫了一下,com的基本上都被注册了。。。

    public static void main(String[] args) { String[] letter = new String[]{"i","m", ...