吴恩达-AI-机器学习课后习题解析-第三周
================================================= sigmod.m =========================================================================
function g = sigmoid(z)
%SIGMOID Compute sigmoid function
% g = SIGMOID(z) computes the sigmoid of z.
% You need to return the following variables correctly
g = zeros(size(z));
% ====================== YOUR CODE HERE ======================
% Instructions: Compute the sigmoid of each value of z (z can be a matrix,
% vector or scalar).
g = 1 ./ (1+exp(-z))
% =============================================================
end

===================================================== predict.m =====================================================================
function p = predict(theta, X)
%PREDICT Predict whether the label is 0 or 1 using learned logistic
%regression parameters theta
% p = PREDICT(theta, X) computes the predictions for X using a
% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)
m = size(X, 1); % Number of training examples
% You need to return the following variables correctly
p = zeros(m, 1);
% ====================== YOUR CODE HERE ======================
% Instructions: Complete the following code to make predictions using
% your learned logistic regression parameters.
% You should set p to a vector of 0's and 1's
%
p = round(sigmoid(X * theta)); % round(>= 0.5) = 1, round(< 0.5) = 0
% =========================================================================
end

================================================= costFunction.m =========================================================================
function [J, grad] = costFunction(theta, X, y)
%COSTFUNCTION Compute cost and gradient for logistic regression
% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the
% parameter for logistic regression and the gradient of the cost
% w.r.t. to the parameters.
% Initialize some useful values
m = length(y); % number of training examples
% You need to return the following variables correctly
J = 0;
grad = zeros(size(theta));
% ====================== YOUR CODE HERE ======================
% Instructions: Compute the cost of a particular choice of theta.
% You should set J to the cost.
% Compute the partial derivatives and set grad to the partial
% derivatives of the cost w.r.t. each parameter in theta
%
% Note: grad should have the same dimensions as theta
%
J = (-y' * log(sigmoid(X * theta)) - (1 - y)' * log(1 - sigmoid(X * theta))) / m;
grad = X' * (sigmoid(X * theta) - y) / m;
% =============================================================
end

吴恩达-AI-机器学习课后习题解析-第三周的更多相关文章
- 吴恩达深度学习课后习题第5课第1周第3小节: Jazz Improvisation with LSTM
目录 Improvise a Jazz Solo with an LSTM Network Packages 1 - Problem Statement 1.1 - Dataset What are ...
- 吴恩达深度学习第4课第3周编程作业 + PIL + Python3 + Anaconda环境 + Ubuntu + 导入PIL报错的解决
问题描述: 做吴恩达深度学习第4课第3周编程作业时导入PIL包报错. 我的环境: 已经安装了Tensorflow GPU 版本 Python3 Anaconda 解决办法: 安装pillow模块,而不 ...
- 吴恩达深度学习第2课第2周编程作业 的坑(Optimization Methods)
我python2.7, 做吴恩达深度学习第2课第2周编程作业 Optimization Methods 时有2个坑: 第一坑 需将辅助文件 opt_utils.py 的 nitialize_param ...
- 吴恩达《机器学习》课程笔记——第六章:Matlab/Octave教程
上一篇 ※※※※※※※※ [回到目录] ※※※※※※※※ 下一篇 这一章的内容比较简单,主要是MATLAB的一些基础教程,如果之前没有学过matlab建议直接找一本相关书籍,边做边学,matl ...
- 吴恩达《机器学习》课程总结(5)_logistic回归
Q1分类问题 回归问题的输出可能是很大的数,而在分类问题中,比如二分类,希望输出的值是0或1,如何将回归输出的值转换成分类的输出0,1成为关键.注意logistics回归又称 逻辑回归,但他是分类问题 ...
- 吴恩达深度学习第1课第4周-任意层人工神经网络(Artificial Neural Network,即ANN)(向量化)手写推导过程(我觉得已经很详细了)
学习了吴恩达老师深度学习工程师第一门课,受益匪浅,尤其是吴老师所用的符号系统,准确且易区分. 遵循吴老师的符号系统,我对任意层神经网络模型进行了详细的推导,形成笔记. 有人说推导任意层MLP很容易,我 ...
- 吴恩达《机器学习》编程作业——machine-learning-ex1:线性回归
❄❄❄❄❄❄❄❄[回到目录]❄❄❄❄❄❄❄❄ 本次编程作业中,需要完成的代码有如下几部分: [⋆] warmUpExercise.m - Simple example function in Octa ...
- 吴恩达《机器学习》课程笔记——第七章:Logistic回归
上一篇 ※※※※※※※※ [回到目录] ※※※※※※※※ 下一篇 7.1 分类问题 本节内容:什么是分类 之前的章节介绍的都是回归问题,接下来是分类问题.所谓的分类问题是指输出变量为有限个离散 ...
- 吴恩达j机器学习之过拟合
五.编程作业: 见:https://www.cnblogs.com/tommyngx/p/9933803.html
随机推荐
- LeetCode OJ:Maximum Subarray(子数组最大值)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- CoreData之增删改查
1. 导入库文件CoreData.framework2. 在iOS的Core Data 中建Data Model文件 此时有三种选择 2.1. 选Data Model(如默认名Model.xcdata ...
- HashMap(HashSet)的实现
0. HashMap(TreeMAP).HashSet.HashTable 的关系 HashMap 的底层则维护着 Node<K, V>[] table; 一个一维数组用于快速访问(只在初 ...
- DEV控件 皮肤问题
今天用cnPack清理了下整个工程的引用单元,清理完,问题来了,TcxPageControl不透明了. 折腾了一会,找到原因,清理单元时将dxSkinscxPCPainter也清掉了,导致皮肤无法正常 ...
- HDU - 6098:Inversion(暴力均摊)
Give an array A, the index starts from 1. Now we want to know B i =max i∤j A j Bi=maxi∤jAj , i≥2 i≥ ...
- ehcache缓存技术的特性
Ehcache是现在最流行的纯Java开源缓存框架,配置简单.结构清晰.功能强大,最初知道它,是从hibernate的缓存开始的.网上中文的EhCache材料以简单介绍和配置方法居多,如果你有这方面的 ...
- 洛谷 P2909 [USACO08OPEN]牛的车Cow Cars
传送门 题目大意: m个车道. 如果第i头牛前面有k头牛,那么这头牛的最大速度会 变为原本的速度-k*D,如果速度小于l这头牛就不能行驶. 题解:贪心 让初始速度小的牛在前面 代码: #include ...
- WPF简单模拟QQ登录背景动画(转)
介绍 之所以说是简单模拟,是因为我不知道QQ登录背景动画是怎么实现的.这里是通过一些办法把它简化了,做成了类似的效果 效果图 大体思路 首先把背景看成是一个4行8列的点的阵距,X轴Y轴都是距离70.把 ...
- git自用笔记
同步远程库:git clone xxx.git [filename] git ls-files: 查看已经添加进暂存区的文件. 在commit前修改一个文件后(假设名为:xxx.file),想撤销时, ...
- (转)安装Android SDK时遇到Failed to rename directory
安装Android SDK时遇到Failed to rename directory E:\Java\Android SDK\android-sdk_r06-windows\android-sdk-w ...