机器学习作业之 Linear Regression with Multiple Variables (Week 2)
来源:互联网 发布:统计查询sql语句 编辑:程序博客网 时间:2024/05/17 18:49
cost function:
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 valuesm = length(y); % number of training examples% You need to return the following variables correctly J = 0;% ====================== YOUR CODE HERE ======================% Instructions: Compute the cost of a particular choice of theta% You should set J to the cost. for i=1:m J = J+(X(i,:)*theta - y(i,:))^2; end J = J/(2*m); % =========================================================================end
granditent descent:
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)%GRADIENTDESCENT Performs gradient descent to learn theta% theta = GRADIENTDESENT(X, y, theta, alpha, num_iters) updates theta by % taking num_iters gradient steps with learning rate alpha% Initialize some useful valuesm = length(y); % number of training examplesJ_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. % theta=theta-alpha*(1/m)*(X'*(X*theta-y)); % ============================================================ % Save the cost J in every iteration J_history(iter) = computeCost(X, y, theta);endend
0 0
- 机器学习作业之 Linear Regression with Multiple Variables (Week 2)
- 机器学习IV. Linear Regression with Multiple Variables (Week 2) 多特征线性回归
- 【Stanford机器学习笔记】2-Linear Regression with Multiple Variables
- Machine Learning week 2 quiz: Linear Regression with Multiple Variables
- 机器学习之2-多变量线性回归(Linear Regression with Multiple Variables)
- 吴恩达 机器学习笔记 Linear Regression with Multiple Variables
- CS229机器学习个人笔记(2)——Linear Regression with Multiple Variables
- (2)Linear Regression with Multiple Variables
- (2)Linear Regression with Multiple Variables
- Linear Regression with Multiple Variables
- Linear regression with multiple variables
- Machine Learning Week 2 Linear Regression with multiple variables in Matlab or Octave
- Machine Learning - IV. Linear Regression with Multiple Variables多变量线性规划 (Week 2)
- [ML of Andrew Ng]Week 2 : Linear Regression with Multiple Variables and Normal Equation
- Coursera机器学习第二周学习笔记——Linear Regression with Multiple Variables
- Regression(3)-------Linear Regression with multiple variables
- Stanford机器学习---第二讲. 多变量线性回归Linear Regression with multiple variables
- 斯坦福 机器学习Andrew NG 第二讲 Linear Regression with multiple variables
- 关联性
- 《数据结构》实验二:线性表实验(上)
- linux GPMC驱动调试笔记
- 关于极光推送的一些步骤
- System
- 机器学习作业之 Linear Regression with Multiple Variables (Week 2)
- Qt5的插件机制(1)--Qt 框架中的插件加载机制概述
- 音视频编码基本概念
- AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别
- 进制转换
- 使用qtcreator-2.6.1创建Application的过程
- 2014.11.19超级复制
- Computer Architecture Top Journal
- 用Python实现ROT13