Coursera-机器学习(吴恩达)第三周-编程作业

这篇博客介绍了Coursera上吴恩达机器学习课程的第三周编程作业,主要内容包括逻辑回归的sigmoid函数实现、代价函数与梯度、使用fminunc优化求解器进行参数最小化以及预测函数predict.m的编写。同时,文章还简要提到了正规化的概念。
摘要由CSDN通过智能技术生成

1、逻辑回归

逻辑回归与线性回归的主要区别在于假设函数,逻辑回归中的假设函数:

                                                                        hθ(x) = g(θ'x)=sgmoid(θ’x)

1)sigmoid 代码实现

% sigmoid 代码实现
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

2)Cost function and gradien

写代码之前首先清楚X、y、theta各是几乘几的矩阵。

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
%   p
  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值