逻辑回归的向量化实现样例

From Ufldl

Jump to: navigation, search
Line 1: Line 1:
-
Logistic回归分析的向量化实现样例
 
-
 
-
【原文】:
 
-
 
-
Consider training a logistic regression model using batch gradient ascent. Suppose our hypothesis is
 
-
 
-
【初译】:
 
-
 
-
试想,采用批量梯度上升法(batch gradient ascent)对逻辑回归模型进行求解(训练),模型如下:
 
-
 
-
【一校】:
 
-
 
我们想用批量梯度上升法对logistic回归分析模型进行训练,其模型如下:
我们想用批量梯度上升法对logistic回归分析模型进行训练,其模型如下:
<math>h_{\theta }\left( x\right) =\dfrac {1} {1+exp\left( -\theta ^{T}x\right) }</math>
<math>h_{\theta }\left( x\right) =\dfrac {1} {1+exp\left( -\theta ^{T}x\right) }</math>
-
【原文】:
+
让我们遵从公开课程视频与CS229教学讲义的符号规范,设 <math>\textstyle x_0=1</math>,于是<math>x\in R^{n+1}</math> ,<math>\theta \in R^{n+1}</math>, <math>\textstyle \theta_0</math> 为截距。我们有m个训练样本{(<math>x^\left( 1\right) </math>,<math>y^\left( 1\right)</math> ) ,...,(<math>x^\left( m\right)</math> ,<math>y^\left( m\right)</math> ) },而批量梯度上升法的更新法则是:<math>\theta :=\theta +\alpha \nabla _{\theta }l\left( \theta \right) </math> ,这里的 <math>l\left( \theta \right) </math> 是对数似然函数,<math>\nabla _{\theta }l\left( \theta \right) </math> 是其导函数。
-
 
+
-
where (following the notational convention from the OpenClassroom videos and from CS229) we let <math>\textstyle x_0=1</math>, so that <math>x\in R^{n+1}</math> and  <math>\theta \in R^{n+1}</math>, and <math>\textstyle \theta_0</math> is our intercept term. We have a training set{(<math>x^\left( 1\right) </math>,<math>y^\left( 1\right)</math> ) ,...,(<math>x^\left( m\right)</math> ,<math>y^\left( m\right)</math> ) } of m examples, and the batch gradient ascent update rule is <math>\theta :=\theta +\alpha \nabla _{\theta }l\left( \theta \right) </math> , where <math>l\left( \theta \right) </math>  is the log likelihood and  <math>\nabla _{\theta }l\left( \theta \right) </math> is its derivative.
+
-
 
+
-
【初译】:
+
-
 
+
-
设 <math>\textstyle x_0=1</math>(符号规范遵从公开课程视频与CS229教学讲义),于是 <math>x\in R^{n+1}</math> , <math>\theta \in R^{n+1}</math>, <math>\textstyle \theta_0</math>为截距。现在,我们有m组样本数据集 {(<math>x^\left( 1\right) </math>,<math>y^\left( 1\right)</math> ) ,...,(<math>x^\left( m\right)</math> ,<math>y^\left( m\right)</math> ) },而批量梯度上升法的规则是: <math>\theta :=\theta +\alpha \nabla _{\theta }l\left( \theta \right) </math> ,这里的<math>l\left( \theta \right) </math> 是对数似然函数,<math>\nabla _{\theta }l\left( \theta \right) </math> 它的导函数。
+
-
 
+
-
【一校】:
+
-
 
+
-
设 <math>\textstyle x_0=1</math>(符号规范遵从公开课程视频与CS229教学讲义),于是<math>x\in R^{n+1}</math> ,<math>\theta \in R^{n+1}</math>, <math>\textstyle \theta_0</math> 为截距。我们有m个训练样本{(<math>x^\left( 1\right) </math>,<math>y^\left( 1\right)</math> ) ,...,(<math>x^\left( m\right)</math> ,<math>y^\left( m\right)</math> ) },而批量梯度上升法的更新法则是: <math>\theta :=\theta +\alpha \nabla _{\theta }l\left( \theta \right) </math> ,这里的 <math>l\left( \theta \right) </math> 是对数似然函数,<math>\nabla _{\theta }l\left( \theta \right) </math> 是其导函数。
+
-
 
+
-
【原文】:
+
-
 
+
-
[Note: Most of the notation below follows that defined in the OpenClassroom videos or in the class CS229: Machine Learning. For details, see either the OpenClassroom videos or Lecture Notes #1 of http://cs229.stanford.edu/ .]
+
-
 
+
-
【初译】:
+
[注:下文的符号规范与<公开课程视频>或<教学讲义CS229:机器学习>中的相同,详细内容可以参见公开课程视频或教学讲义#1http://cs229.stanford.edu/]
[注:下文的符号规范与<公开课程视频>或<教学讲义CS229:机器学习>中的相同,详细内容可以参见公开课程视频或教学讲义#1http://cs229.stanford.edu/]
-
【一校】:
+
于是,我们需要如下计算梯度:
-
 
+
-
[注:下文的符号规范与<公开课程视频>或<教学讲义CS229:机器学习>中的相同,详细内容可以参见公开课程视频或教学讲义#1http://cs229.stanford.edu/]
+
-
 
+
-
【原文】:
+
-
 
+
-
We thus need to compute the gradient:
+
-
 
+
-
【初译】:
+
-
 
+
-
于是,我们要计算一下梯度(gradient):
+
-
 
+
-
【一校】:
+
-
 
+
-
于是,我们要计算一下梯度(gradient):
+
<math>\nabla _{\theta }l\left( \theta \right) =\sum _{i=1}^{m}\left( y^{\left( i\right) }-h_{\theta }\left( x^{\left( i\right) }\right) \right) x_{j}^{\left( i\right) }</math>
<math>\nabla _{\theta }l\left( \theta \right) =\sum _{i=1}^{m}\left( y^{\left( i\right) }-h_{\theta }\left( x^{\left( i\right) }\right) \right) x_{j}^{\left( i\right) }</math>

Revision as of 14:54, 14 March 2013

Personal tools