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 + ...
随机推荐
- 无法查找或打开 PDB 文件解决办法
用VS调试程序时,有时会在VS底部的“输出”框中提示“无法查找或打开 PDB 文件”.这该怎么解决呢? 下面,我们以VS2013为例,来教大家解决办法. 工具/原料 VS 方法/步骤 打开VS20 ...
- java的web配置文件的“<load-on-startup>的说明[转]
<servlet> <servlet-name>log4jInitServlet</servlet-name> <servlet-class>org.s ...
- 数字图像处理:基于MATLAB的车牌识别项目 标签: 图像处理matlab算法 2017-06-24 09:17 98人阅读 评论(0)
学过了数字图像处理,就进行一个综合性强的小项目来巩固一下知识吧.前阵子编写调试了一套基于MATLAB的车牌识别的项目的代码.今天又重新改进了一下代码,识别的效果好一点了,也精简了一些代码.这里没有使用 ...
- Firefox 43无法安装xpi的问题
Firefox 43无法安装xpi的问题 说明:Firefox 42将默认禁止安装未签名扩展 强制禁用这个首选项(高级用户): 你可以在 Firefox 配置编辑页面 (about:config ...
- a 标签 name 属性 页面定位 (二)
<a href="to_url#somewhere">名字</a> <a name="somewhere">名字</a ...
- mysql建外键失败
1. 修改引擎:(设计表-->选项-->引擎:InnoDB) 2. 检查外键类型是否一致:
- route -A inet6查看路由 getnameinfo failed [UNKNOWN]解决方案
route -A inet6查看路由 getnameinfo failed [UNKNOWN]解决方案, 结果如下: route -A inet6 -n 查看即可
- Python 数据分析—第七章 数据归整:清理、转换、合并、重塑
一.数据库风格的Dataframe合并 import pandas as pd import numpy as np df1 = pd.DataFrame({'1key':['b','b','a',' ...
- mybatis 基础教程
1.引用mybatis.jar包,以后依赖包. 2.配置映射文件(一个是主配置文件,一个是sql映射文件),注意,mapper.xml 文件必须和dao放在一起. 3.mybatis.xml文件说明 ...
- INDEX--索引相关信息查看
--============================================== --查看可能缺失的索引 SELECT mig.* ,migs.* ,mid.* FROM sys.dm ...