IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> 《Machine Learning Fundamentals》Class Notes -- Chapter Two Regression(待补) -> 正文阅读

[人工智能]《Machine Learning Fundamentals》Class Notes -- Chapter Two Regression(待补)

Figure 1

Introduction

Linear regression attempts to get a function g that can use the attributes of the input to predict the resulting output.
g ( x i ) = w 1 x 1 + w 2 x 2 + . . . + w m x m + b = w T x + b , ? m a k e s ? g ( x i ) ? y i g(x_i)=w_1x_1+w_2x_2+...+w_mx_m+b=w^Tx+b, \ makes\ g(x_i)\simeq y_i g(xi?)=w1?x1?+w2?x2?+...+wm?xm?+b=wTx+b,?makes?g(xi?)?yi?

Obviousely, w,b determine the result of g(x), and our goal is to choice the best w,b to minimize the error.
Ususally, we use MSE(Mean Square Error, E = ∑ n [ y ( n ) ? ( w T x ( n ) + b ) ] 2 E=\sum_{n}[y^{(n)}-(w^Tx^{(n)}+b)]^2 E=n?[y(n)?(wTx(n)+b)]2) as linear regression’s loss funtion. But, why?

Why we use MES as loss function

We assume: given x, then the distribution of y satisfies the Gaussian distribution.
Maybe you want to say, there are many kinds of distribution in reality, why Gaussian distribution?
The CLT(central limit theorem) can explain this probelm.

In probability theory, the central limit theorem (CLT) establishes that, in many situations, when independent random variables are summed up, their properly normalized sum tends toward a normal distribution (informally a bell curve) even if the original variables themselves are not normally distributed.

We suppose y satisfies the following Gaussian distribution:
p ( y ∣ x ) ~ N ( w T x + b , σ 2 ) p(y | x)\sim N(w^Tx+b,\sigma^2 ) p(yx)N(wTx+b,σ2)
Figure 2
So, l o g ? l i k e l i h o o d ? f u n c t i o n ∝ L ( w , b ) log-likelihood\ function \propto L(w,b) log?likelihood?functionL(w,b), and
L ( w , b ) = log ? ( ∏ n e x p ( ? 1 2 σ 2 ( y ( n ) ? w T x ( n ) ? b ) 2 ) ) = ? 1 2 σ 2 ∑ n ( y ( n ) ? w T x ( n ) ? b ) 2 ? w , b = a r g m a x w , b L ( w , b ) ? w , b = a r g m i n w , b ∑ n ( y ( n ) ? w T x ( n ) ? b ) 2 \begin{matrix} L(w,b)&=&\log (\prod_{n}exp(-\frac{1}{2\sigma^2}(y^{(n)}-w^Tx^{(n)}-b)^2)) \\ \\ &=&-\frac{1}{2\sigma^2} \sum_{n} (y^{(n)}-w^Tx^{(n)}-b)^2 \\ \\ \Rightarrow w,b &=& argmax_{w,b}L(w,b) \\ \\ \Rightarrow w,b &=& argmin_{w,b}\sum_n(y^{(n)}-w^Tx^{(n)}-b)^2 \end{matrix} L(w,b)?w,b?w,b?====?log(n?exp(?2σ21?(y(n)?wTx(n)?b)2))?2σ21?n?(y(n)?wTx(n)?b)2argmaxw,b?L(w,b)argminw,b?n?(y(n)?wTx(n)?b)2?
Is this a bit like Euclidean Distance(geometric meaning)?
That’s why we use MES as loss functoin, and our gold is minnimize it. This also called OSL(Ordinary least squares).
The specific method is to make the partial derivatives with respect to w and b to be 0.
Y = [ y ( 1 ) y ( 2 ) ? y ( n ) ] X = [ x ( 1 ) x ( 2 ) ? x ( n ) ] = [ x 1 ( 1 ) ? x m ( 1 ) x 1 ( 2 ) ? x m ( 2 ) ? x 1 ( n ) ? x m ( n ) ] b = [ b ( 1 ) b ( 2 ) ? b ( n ) ] , ? b 1 = b 2 = ? = b n \begin{matrix} Y&=&\begin{bmatrix} y^{(1)} \\ y^{(2)} \\ \vdots \\ y^{(n)} \\ \end{bmatrix} \\ X&=&\begin{bmatrix} x^{(1)} \\ x^{(2)} \\ \vdots \\ x^{(n)} \\ \end{bmatrix} &=&\begin{bmatrix} x_1^{(1)} & \cdots & x_m^{(1)} \\ x_1^{(2)} & \cdots & x_m^{(2)} \\ &\vdots & \\ x_1^{(n)} & \cdots & x_m^{(n)} \\ \end{bmatrix} \\ b&=&\begin{bmatrix} b^{(1)} \\ b^{(2)} \\ \vdots \\ b^{(n)} \\ \end{bmatrix} &,&\ b_1=b_2=\cdots =b_n \end{matrix} YXb?===???????y(1)y(2)?y(n)?????????????x(1)x(2)?x(n)?????????????b(1)b(2)?b(n)????????=,????????x1(1)?x1(2)?x1(n)???????xm(1)?xm(2)?xm(n)??????????b1?=b2?=?=bn??
So, the loss function can be represented as E = ( Y ? X w ? b ) T ( Y ? X w ? b ) E=(Y-Xw-b)^T(Y-Xw-b) E=(Y?Xw?b)T(Y?Xw?b).
It’s easy to discover that the values of b i b_i bi? are same, and we can simplify the original function.
We might as well change the representation of w and treat b as a constant weight of 1: w = ( w 1 ; ? ? ; w n ; b ) w=(w_1;\cdots;w_n;b) w=(w1?;?;wn?;b).
X = [ x ( 1 ) ; 1 x ( 2 ) ; 1 ? x ( n ) ; 1 ] = [ x 1 ( 1 ) ? x m ( 1 ) 1 x 1 ( 2 ) ? x m ( 2 ) 1 ? x 1 ( n ) ? x m ( n ) 1 ] X=\begin{bmatrix} x^{(1)};1 \\ x^{(2)};1 \\ \vdots \\ x^{(n)};1 \\ \end{bmatrix} =\begin{bmatrix} x_1^{(1)} & \cdots & x_m^{(1)} & 1\\ x_1^{(2)} & \cdots & x_m^{(2)} & 1\\ &\vdots & \\ x_1^{(n)} & \cdots & x_m^{(n)} & 1\\ \end{bmatrix} X=??????x(1);1x(2);1?x(n);1???????=???????x1(1)?x1(2)?x1(n)???????xm(1)?xm(2)?xm(n)??111????????
then, E = ( Y ? X w ) T ( Y ? X w ) E=(Y-Xw)^T(Y-Xw) E=(Y?Xw)T(Y?Xw).

Derivations of the loss function

在这里插入图片描述

It is easy to discover that E is a convex function, so the optimal solution of function is obtained when the the partial derivative with respect to w is 0.
E = ( Y ? X w ) T ( Y ? X w ) = ( Y T ? w T X T ) ( Y ? X w ) = Y T Y ? Y T X w ? w T X T Y + w T X T X w S o , ? ? E ? w = ? ( Y T X ) T ? X T Y + [ X T X + ( X T X ) T ] w = ? 2 X T Y + 2 X T X w = ? 2 X T ( Y ? X w ) \begin{matrix} E&=& (Y-Xw)^T(Y-Xw)\\ \\ &=& (Y^T-w^TX^T)(Y-Xw)\\ \\ &=& Y^TY-Y^TXw-w^TX^TY+w^TX^TXw\\ \\ So,\ \frac{\partial E}{\partial w} &=& -(Y^TX)^T-X^TY+[X^TX+(X^TX)^T]w \\ \\ &=& -2X^TY+2X^TXw \\ \\ &=& -2X^T(Y-Xw) \end{matrix} ESo,??w?E??======?(Y?Xw)T(Y?Xw)(YT?wTXT)(Y?Xw)YTY?YTXw?wTXTY+wTXTXw?(YTX)T?XTY+[XTX+(XTX)T]w?2XTY+2XTXw?2XT(Y?Xw)?
Then let the partial derivative with respect to w be 0:
X T ( Y ? X w ) = 0 X T Y = X T X w w = [ X T X ] ? 1 X T Y \begin{matrix} X^T(Y-Xw) &=& 0 \\ \\ X^TY &=& X^TXw \\ \\ w&=&[X^TX]^{-1}X^TY \end{matrix} XT(Y?Xw)XTYw?===?0XTXw[XTX]?1XTY?
Obviously, we need to find the inverse of X T X X^TX XTX, but it is usually not full-rank matrix or positive definite matrix. Then, you need to use gradient descent, and the source code of sklearn also use gradient descent.
Other than that, you might want to ask why the formula is different from the one in the textbook. So, I hava to say the textbook is real BAD!

Code

X = np.c_[X, np.ones(np.shape(X)[0], 1)]
w_bext = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Y)

TODO

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-03-13 21:47:25  更:2022-03-13 21:51:14 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2025年1日历 -2025/1/9 16:00:14-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码