码迷,mamicode.com
首页 > 其他好文 > 详细

机器学习基础教程:线性建模fitlinear

时间:2016-07-22 19:27:59      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:

Define the data
Change these to use a different dataset

x = [1;3;5];
t = [4.8;11.1;17.2];
N = length(x); % 3

Compute the various averages required

x??=1/N?nxn

m_x = sum(x)/N;

t?=1/N?ntn

m_t = sum(t)/N;

xt???=1/N?ntn?xn

m_xt = sum(t.*x)/N;

x2????=1/N?nx2n

m_xx = sum(x.*x)/N;

Compute w1 (gradient) (Equation 1-10)

w1=xt????x??t?x2?????x??2

w_1 = (m_xt - m_x*m_t)/(m_xx - m_x^2);

Compute w0 (intercept) (Equation 1-8)

w0=t??w1x??

w_0  = m_t - w_1*m_x;

Plot the data and linear fit

%% Plot the data and linear fit
figure(1);hold off
plot(x,t,‘bo‘,‘markersize‘,10,‘linewidth‘,2)
xplot = [0 6];
xlim(xplot)
hold on
plot(xplot,w_0+w_1*xplot,‘r‘,‘linewidth‘,2)
xlabel(‘x‘);
ylabel(‘t‘);

技术分享

关于Machine Learning更多讨论与交流,敬请关注本博客新浪微博songzi_tea.

机器学习基础教程:线性建模fitlinear

标签:

原文地址:http://blog.csdn.net/songzitea/article/details/51992101

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!