1.warmUpExercise:

function A = warmUpExercise()
%WARMUPEXERCISE Example function in octave
% A = WARMUPEXERCISE() is an example function that returns the 5x5 identity matrix A = [];
% ============= YOUR CODE HERE ==============
% Instructions: Return the 5x5 identity matrix
% In octave, we return values by defining which variables
% represent the return values (at the top of the file)
% and then set them accordingly. A=eye(5); % =========================================== end

2.Computing Cost:

function J = computeCost(X, y, theta)
%COMPUTECOST Compute cost for linear regression
% J = COMPUTECOST(X, y, theta) computes the cost of using theta as the
% parameter for linear regression to fit the data points in X and y % Initialize some useful values
m = length(y); % number of training examples % ====================== YOUR CODE HERE ======================
% Instructions: Compute the cost of a particular choice of theta
% You should set J to the cost. pred=X*theta;
errors=(pred-y).^2;
% You need to return the following variables correctly
J = 1/(2*m)*sum(errors); % ========================================================================= end

3.Gradient Desecnt:

换成矩阵的形式操作;

function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
%GRADIENTDESCENT Performs gradient descent to learn theta
% theta = GRADIENTDESCENT(X, y, theta, alpha, num_iters) updates theta by
% taking num_iters gradient steps with learning rate alpha % Initialize some useful values
m = length(y); % number of training examples
J_history = zeros(num_iters, 1); for iter = 1:num_iters % ====================== YOUR CODE HERE ======================
% Instructions: Perform a single gradient step on the parameter vector
% theta.
%
% Hint: While debugging, it can be useful to print out the values
% of the cost function (computeCost) and gradient here.
% tmp=X'*(X*theta-y);
theta=theta-alpha/m*tmp; % ============================================================ % Save the cost J in every iteration
J_history(iter) = computeCost(X, y, theta); end end

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

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

    1.Feature Normalization: 归一化的处理 function [X_norm, mu, sigma] = featureNormalize(X) %FEATURENORMALIZE ...

  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++] Function Template - optional parameter

    Function Template

  2. [C++] How to prevent memory leaks

    How to prevent memory leaks ? overload new/delete

  3. MemoryUsage:监测java虚拟机内存使用

    通过MemoryUsage可以查看Java 虚拟机的内存池的内存使用情况.MemoryUsage类有四个值(均以字节为单位): ===Init=== java虚拟机在启动的时候向操作系统请求的初始内存 ...

  4. PBOC电子现金的交易流程

    做一个电子现金的交易: 第一步当然是选中当前的应用, 方法是调用select命令, 传入当前的应用AID号, 如果卡片的状态码返回9000,则表示选中成功. 下面举一个例子: 发送: 00 a4 04 ...

  5. mongo学习-稀疏索引

    因为,如果要创建唯一索引,那么如果这个值有好几个为Null的,所以也会导致我们创建索引失败,那么我们可以引进系数索引这个概念,它可以做到,支持如果值存在的情况,它必须是唯一的,我们可以 将 uniqu ...

  6. 我是如何在SQLServer中处理每天四亿三千万记录的(转)

    出处:http://www.cnblogs.com/marvin/p/HowCanIHandleBigDataBySQLServer.html 首先声明,我只是个程序员,不是专业的DBA,以下这篇文章 ...

  7. aspnetcore的那些actionresult们

    比MVC5多了n个actionresult,傻傻分不清,整理了下,妈妈再也不用担心了 https://docs.asp.net/projects/api/en/latest/autoapi/Micro ...

  8. 第05章 管理ElasticSearch

    本章内容 如何选择正确的目录实现,使得ElasticSearch能够以高效的方式访问底层I/O系统. 如何配置发现模块来避免潜在的问题. 如何配置网关模块以适应我们的需求. 恢复模块能带来什么,以及如 ...

  9. Mathcad操作tips:算式输入、变量定义与计算

    算式输入 1. 数字与符号相乘,输入时不必手动输入乘号(“*”). 2. 以下有助于算式的可视化:a. 使用Math工具栏输入,并合理使用tab键:b. 合理使用空格键. 3. 输入开根号时,可用快捷 ...

  10. mysql中判断记录是否存在方法比较【转】

    把数据写入到数据库的时,常常会碰到先要检测要插入的记录是否存在,然后决定是否要写入. 我这里总结了判断记录是否存在的常用方法: sql语句:select count(*) from tablename ...