%% Machine Learining----Linear Regression
close all
clear %%data load
Year = linspace(,,);
Price = [,2.5,2.9,3.147,4.515,4.903,5.365,5.704,6.853,7.791,8.561,,11.28,12.9]; %%train data
alpha = 0.01;
theta = [,];
obj_old = 1e10;
tor = 1e-; tic;
for time = :
delta = zeros(,);
objective = ;
hypothesis = theta() + theta() * Year;
drawnow;
subplot(,,);
plot(Year,Price,'rx',Year,hypothesis);
for i = :
delta = (theta() + theta() * Year(i) - Price(i)) * [,Year(i)] + delta;
objective = (theta() + theta() * Year(i) - Price(i)) * (theta() + theta() * Year(i) - Price(i))+ objective;
end
theta = theta - alpha * delta / ; fprintf('objective is %.4f\n', objective);
if abs(obj_old - objective) < tor
fprintf('torlerance is samller than %.4f\n', tor);
break;
end
obj_old = objective;
subplot(,,);
plot(toc,obj_old);
axis([ ]) %xmin是x最小,xmax是x最大,ymin,ymax类似
hold on;
end

最新文章

  1. Android 剪贴板详解
  2. Ubuntu搭建NFS
  3. DPM检测模型 训练自己的数据集 读取接口修改
  4. php session_start() 非常慢 问题原因查找
  5. android如何获取到启动类的包和类路径
  6. 我所了解的WEB开发(4) - 神奇的URL
  7. Linux_常用命令_04_挂载
  8. 匿名函数自执行原理和instanceof运算符执行原理
  9. 子字符查找KMP算法 - 子串自匹配索引表
  10. Oracle使用游标删除所有用户数据表中的所有记录脚本
  11. 背景图片蒙上一层颜色(背景图片无法用rgba调整透明度!)
  12. xamarin android 文件选择
  13. 传统asp.net小心 async/await坑
  14. oracle12c的日志查看
  15. Facade(外观)模式
  16. ssh2——Interceptor拦截器
  17. Insert插入语句中带有select语句
  18. python字符串常用
  19. mysql的InnoDB 数据库引擎TableSpace Exists 问题
  20. iOS:网页视图控件UIWebView的详解

热门文章

  1. python实现网速控制,限制上传下载速度
  2. 微信小程序 项目实战(二)board 首页
  3. Pat(Advanced Level)Practice--1018(Public Bike Management)
  4. android项目笔记(一)
  5. 【转载】lvs为何不能完全替代DNS轮询
  6. poj2406--Power Strings(kmp:求循环串的次数)
  7. 混合minxins
  8. mac系统不同java版本切换
  9. 【 D3.js 进阶系列 — 1.2 】 读取 CSV 文件时乱码的解决方法
  10. 读写ini配置文件 .