Multivariate Linear Regression代码-Andrew NG Machine Learning Ex3
来源:互联网 发布:淘宝账号可以注销了 编辑:程序博客网 时间:2024/05/09 13:26
大神Andrew NG课程Exercise 2作业代码,题目详见网页:
点击打开链接
matlab实现代码如下所示:
x = load('ex3x.dat');y = load('ex3y.dat');m = length(x);x = [ones(m,1), x];% Feature Scalingsigma = std(x);mu = mean(x);x(:,2) = (x(:,2) - mu(2))./ sigma(2);x(:,3) = (x(:,3) - mu(3))./ sigma(3);alpha = [0.01, 0.03, 0.1, 0.3, 1.0, 1.3]; %% Your initial learning rate %%plotstyle = {'b', 'r', 'g', 'k', 'b--', 'r--'};J = zeros(50, 1); for k = 1:6theta = zeros(size(x(1,:)))'; % initialize fitting parametersfor num_iterations = 1:50 J(num_iterations) = ((x*theta-y)'*(x*theta-y))/(2*m); %% Calculate your cost function here %% theta = theta - alpha(k)*((x*theta-y)'*x)'/m; %% Result of gradient descent update %%endif alpha(k)==1 thetaBest = theta;end % now plot J% technically, the first J starts at the zero-eth iteration% but Matlab/Octave doesn't have a zero indexhold on;plot(0:49, J(1:50),char(plotstyle(k)));endxlabel('Number of iterations');ylabel('Cost J');legend('0.01', '0.03', '0.1', '0.3', '1.0', '1.3');price_grad_desc = dot(thetaBest, [1, (1650 - mu(2))/sigma(2), (3 - mu(3))/sigma(3)]);% Normal Equation% Reload Data.x = load('ex3x.dat');y = load('ex3y.dat');m = length(x);x = [ones(m,1), x];theta_normal = (x' * x)\x' * y;price_normal = dot(theta_normal, [1, 1650, 3]);
0 0
- Multivariate Linear Regression代码-Andrew NG Machine Learning Ex3
- #“Machine Learning”(Andrew Ng)#Week 2_1:Multivariate Linear Regression
- Linear Regression代码-Andrew NG Machine Learning Ex2
- Andrew Ng Machine Learning 专题【Linear Regression】
- Machine Learning by Andrew Ng ---Linear Regression with one variable
- Machine Learning by Andrew Ng---Linear Regression with multiple variables
- Machine Learning -- Linear Regression with Multiple Variables(Andrew Ng)
- Machine Learning -- Linear Regression with Multiple Variables(Andrew Ng)
- [Machine Learning (Andrew NG courses)]II. Linear Regression with One Variable
- [Machine Learning (Andrew NG courses)]IV.Linear Regression with Multiple Variables
- Machine Learning 线性回归( Linear Regression) Andrew Ng 课程练习 Matlab Script 详细解析
- Andrew NG 《machine learning》week 2,class2 —Multivariaze Linear Regression
- #“Machine Learning”(Andrew Ng)#Week 1_1:Introduction/Supervised/Un supervised/Linear regression
- 机器学习 Machine Learning(by Andrew Ng)----第二章 单变量线性回归(Linear Regression with One Variable)
- 机器学习 Machine Learning(by Andrew Ng)----第三章 多变量线性回归(Linear Regression with multiple variable)
- ANDREW Ng教授的机器学习(Machine Learning)学习笔记(2)-- 线性回归模型(Linear regression model)
- Machine Learning by Andrew Ng --- Logistic Regression with two classes
- Machine Learning by Andrew Ng --- Logistic Regression by using Regularization
- 慢慢蜕变-从思想意识上开始转变
- SRAtoolkit使用
- 对C语言回调函数的一点感悟
- js清空数组的三种方法
- java中This关键字
- Multivariate Linear Regression代码-Andrew NG Machine Learning Ex3
- Java:字符乱码问题
- Java Web项目Server窗口NullPointerException问题
- Linux 系统应用编程——网络编程(基础篇)
- Linux中各种终端的解释
- linux(ubuntu)单片机用网线ping 不通电脑(已解决)
- Block的基本概念
- libevent8
- 表的修改与数据完整性