Machine learning 吴恩达第二周coding作业(必做题)
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作业(必做题)的更多相关文章
- Machine learning吴恩达第二周coding作业(选做)
1.Feature Normalization: 归一化的处理 function [X_norm, mu, sigma] = featureNormalize(X) %FEATURENORMALIZE ...
- Machine Learning——吴恩达机器学习笔记(酷
[1] ML Introduction a. supervised learning & unsupervised learning 监督学习:从给定的训练数据集中学习出一个函数(模型参数), ...
- Machine learning吴恩达第三周 Logistic Regression
1. Sigmoid function function g = sigmoid(z) %SIGMOID Compute sigmoid function % g = SIGMOID(z) compu ...
- Deap Learning (吴恩达) 第一章深度学习概论 学习笔记
Deap Learning(Ng) 学习笔记 author: 相忠良(Zhong-Liang Xiang) start from: Sep. 8st, 2017 1 深度学习概论 打字太麻烦了,索性在 ...
- 吴恩达机器学习笔记38-决策下一步做什么(Deciding What to Do Next Revisited)
我们已经讨论了模型选择问题,偏差和方差的问题.那么这些诊断法则怎样帮助我们判断,哪些方法可能有助于改进学习算法的效果,而哪些可能是徒劳的呢? 让我们再次回到最开始的例子,在那里寻找答案,这就是我们之前 ...
- Github | 吴恩达新书《Machine Learning Yearning》完整中文版开源
最近开源了周志华老师的西瓜书<机器学习>纯手推笔记: 博士笔记 | 周志华<机器学习>手推笔记第一章思维导图 [博士笔记 | 周志华<机器学习>手推笔记第二章&qu ...
- 我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)【中英双语】
我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)[中英双语] 视频地址:https://www.bilibili.com/video/av9912938/ t ...
- 【吴恩达课后编程作业】第二周作业 - Logistic回归-识别猫的图片
1.问题描述 有209张图片作为训练集,50张图片作为测试集,图片中有的是猫的图片,有的不是.每张图片的像素大小为64*64 吴恩达并没有把原始的图片提供给我们 而是把这两个图片集转换成两个.h5文件 ...
- 【吴恩达课后测验】Course 1 - 神经网络和深度学习 - 第二周测验【中英】
[中英][吴恩达课后测验]Course 1 - 神经网络和深度学习 - 第二周测验 第2周测验 - 神经网络基础 神经元节点计算什么? [ ]神经元节点先计算激活函数,再计算线性函数(z = Wx + ...
随机推荐
- POST 与 GET请求区别
- Qt Signal and Slot
Qt4中的信号槽 Qt4中的信号槽是通过SIGNAL,SLOT两个宏,将参数转换成字符串.Qt编译前,会从源码的头文件中提取由signal和slot声明的信号和槽的函数, 将其组成一张信号和槽对应的字 ...
- SqlServer——系统函数
1) CASE CASE有两种使用形式:一种是简单的CASE函数,另一种是搜索型的CASE函数. [1]简单的 CASE 函数 Format: CASE input_expression WHEN w ...
- javascript中的replace()方法
javascript中有很多很好用的操作字符串和数组的方法,replace()就是其中一个. 看看基本用法 var str = '1234512345'; var newStr = str.repla ...
- Red Hat 6.5 网络yum源的配置
第一次接触Linux系统,用虚拟机安装了一个rad hat6.5版本64位的,傻瓜式安装.安装好之后简单的写了一个C代码,进行gcc编译的时候,提示没有该命令,上网查找了一下说没有安装gcc编译器,用 ...
- cs231n(一)
1.Nearest Neighbor Classifier 计算未分类数据(图片)与已标记类别的训练数据(training set)的距离(L1,L2等距离),然后返回与训练数据(图片)最小距离的图片 ...
- linux查看操作系统版本信息
linux查看操作系统版本信息 摘自:https://www.cnblogs.com/vaelailai/p/7545166.html 一.linux下如何查看已安装的centos版本信息: 1.L ...
- wins 软件安装
1.x86 x64区别86就是原来的32位操作系统64就是现在比较新的64位操作系统
- python 中面向对象编程简单总结1
1.类的定义方式 class ClassName(object): #object 表示继承的类,默认为object pass 类的使用类似函数的调用,也可以认为是调用了一次模板来创建一个实例. 2. ...
- 编写高质量代码改善C#程序的157个建议——建议154:不要过度设计,在敏捷中体会重构的乐趣
建议154:不要过度设计,在敏捷中体会重构的乐趣 有时候,我们不得不随时更改软件的设计: 如果项目是针对某个大型机构的,不同级别的软件使用者,会提出不同的需求,或者随着关键岗位人员的更替,需求也会随个 ...