Coursera Machine Learning 第三周 quiz Programming Exercise 2: Logistic Regression
来源:互联网 发布:师洋的淘宝店是正品吗 编辑:程序博客网 时间:2024/06/05 18:48
sigmoid.m
function g = sigmoid(z)%SIGMOID Compute sigmoid functoon% J = 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
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 valuesm = 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%S=sigmoid(X*theta);J=((-y'*log(S))-((1-y')*log(1-S)))/m;grad=(S-y)'*X/m;% =============================================================endpredict.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 correctlyp = 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));% =========================================================================endcostFunctionReg.m
function [J, grad] = costFunctionReg(theta, X, y, lambda)%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using% theta as the parameter for regularized logistic regression and the% gradient of the cost w.r.t. to the parameters. % Initialize some useful valuesm = 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 thetaT = theta;T(1) = 0;S = sigmoid(X * theta);J = ( (-y' * log(S)) - ((1 - y') * log(1-S)) ) / m + lambda / (2 * m) * sum(T .^ 2);grad = (S - y)' * X / m + lambda / m * T';% =============================================================end
0 0
- Coursera Machine Learning 第三周 quiz Programming Exercise 2: Logistic Regression
- Coursera Machine Learning 第三周 quiz Logistic Regression
- Coursera Machine Learning Week 3 - Programming Exercise 2: Logistic Regression
- Programming Exercise 2: Logistic Regression Machine Learning
- Coursera Machine Learning 第二周 quiz Programming Exercise 1: Linear Regression
- Coursera Machine Learning 第五周 quiz Programming Exercise 4: Neural Networks Learning
- Machine Learning week 3 quiz: programming assignment-Logistic Regression
- Coursera Machine Learning 第七周 quiz Programming Exercise 6: Support Vector Machines
- Coursera Machine Learning 第八周 quiz Programming Exercise 7 K-means Clustering and Principal Component
- Coursera Machine Learning 第三周 quiz Regularization
- Machine Learning week 3 programming exercise logistic regression
- Coursera Machine Learning 第六周 Programming Exercise 5: Regularized Linear Regression and Bias
- Machine Learning week 3 quiz : Logistic Regression
- Machine Learning week 3 quiz : Logistic Regression
- Coursera Machine Learning 课程笔记之第三周:逻辑回归(Logistic Regression)
- Coursera Machine Learning 第四周 quiz Programming Exercise 3 Multi-class Classification and Neural
- Machine Learning week 2 quiz: programming assignment-Linear Regression
- Coursera Machine Learning Week 3.1: Logistic Regression
- C++类的虚函数表
- DisallowedHost: Invalid HTTP_HOST header: '192.168.0.136'. You may need to add u'192.168.0.136' to A
- POJ2246 水
- SpringMVC 笔记--拦截器--interceptor
- SAX解析示例
- Coursera Machine Learning 第三周 quiz Programming Exercise 2: Logistic Regression
- Redis和Memcache的区别分析
- 如何设置谷歌Chrome浏览器打开新的标签页为指定网页?
- boundingRectWithSize:options:attributes:context
- Cocos2dx-3.2 数学类Vec2/Size/Rect
- MAC下安装多版本Java JDK和切换几种方式
- linux/android sdcard framwork
- Java 1.5 新特性之(Java Web Start)
- linux之如何快速在文本里面写入内容