[Coursera机器学习]Logistic Regression WEEK3编程作业
来源:互联网 发布:java程序员适合用mac吗 编辑:程序博客网 时间:2024/06/13 21:33
1.1 Visualizing the data
To help you get more familiar with plotting, we have left plotData.m empty so you can try to implement it yourself. However, this is an optional(ungraded) exercise. We also provide our implementation below so you can copy it or refer to it.
% Find Indices of Positive and Negative Examplespos = find(y==1); neg = find(y == 0);% Plot Examplesplot(X(pos, 1), X(pos, 2), 'k+','LineWidth', 2, ...'MarkerSize', 7);plot(X(neg, 1), X(neg, 2), 'ko', 'MarkerFaceColor', 'y', ...'MarkerSize', 7);
1.2.1 Warmup exercise: sigmoid function
Your rst step is to implement this function in sigmoid.m so it can be called by the rest of your program. When you are nished, try testing a few values by calling sigmoid(x) at the Octave/MATLAB command line.
% ====================== 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));
1.2.2 Cost function and gradient
Now you will implement the cost function and gradient for logistic regression.
Complete the code in costFunction.m to return the cost and gradient.
Recall that the cost function in logistic regression is:
J = (1 / m) * (-y' * log(sigmoid(X * theta)) - (1-y)' * log(1 - sigmoid(X*theta)));grad = (1 / m) * X' * (sigmoid(X * theta) - y);
1.2.4 Evaluating logistic regression
Another way to evaluate the quality of the parameters we have found is to see how well the learned model predicts on our training set. In this part, your task is to complete the code in predict.m. The predict functionwill produce “1” or “0” predictions given a dataset and a learned parameter vector
% ====================== 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) )
2.3 Cost function and gradient
Now you will implement code to compute the cost function and gradient for regularized logistic regression. Complete the code in costFunctionReg.m to return the cost and gradient.
Recall that the regularized cost function in logistic regression is:
% ====================== 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 thetan = size(theta, 1);% You should not regularize theta(1)theta_reg = [0; theta(2:n)];J = (1 / m) * (-y' * log(sigmoid(X * theta)) - (1-y)' * log(1 - sigmoid(X*theta))) + lambda * (1 / (2 * m)) * sum(theta_reg .^ 2);grad = (1 / m) * X' * (sigmoid(X * theta) - y) + lambda * (1 / m) * theta_reg;
- [Coursera机器学习]Logistic Regression WEEK3编程作业
- [机器学习]week3编程作业:Logistic Regression
- Stanford 机器学习 Week3 作业 Logistic Regression
- Logistic Regression WEEK3编程作业
- Coursera机器学习 week3 逻辑回归 编程作业代码
- Coursera ML笔记 -----week3 Logistic Regression
- [Coursera机器学习]Linear Regression WEEK2编程作业
- Coursera Ng机器学习编程作业1:Linear Regression
- Andrew NG 机器学习 Logistic Regression 第三周编程作业
- Coursera机器学习课程笔记(3) Logistic Regression
- [机器学习] Coursera ML笔记 - 逻辑回归(Logistic Regression)
- Coursera机器学习-第三周-逻辑回归Logistic Regression
- Coursera机器学习 week3 assignment
- Coursera机器学习 Week3 笔记
- [Coursera机器学习]Regularized Linear Regression and Bias v.s. Variance WEEK6编程作业
- Coursera deep learning 吴恩达 神经网络和深度学习 第二周 编程作业 Logistic Regression with a Neural Network mindset
- 机器学习 Logistic Regression
- 机器学习 logistic regression
- POJ 3067【树状数组】
- 双色汉诺塔
- 浅谈CSRF攻击方式
- JAVA 中BIO,NIO,AIO的理解
- 百度外卖编程题练习笔记
- [Coursera机器学习]Logistic Regression WEEK3编程作业
- NORFlash协议层
- HDU 1556【线段树区间更新】
- lpa 半监督学习 之--标签传播算法
- java容器 -- 遍历Map中的内容
- Android全球定位系统GPS实时获取位置-Oak先生
- 一、H5全景图-朋友圈全景图-720°全景-VR -----工具使用
- BMT硬件之系统(一):单片机、DSP、嵌入式、微控制器的区分
- HDU 1207