简体   繁体   English

关于逻辑回归和线性回归的问题

[英]Questions on logistic and linear regression

I'm trying to understand logistic and linear regression and was able to understand the theory behind it (doing andrew ng course).我正在尝试理解逻辑回归和线性回归,并且能够理解其背后的理论(做安德鲁 ng 课程)。

We have X -> given features -> matrix of (m , n+1) where m - no.我们有 X -> 给定特征 -> (m , n+1) 的矩阵,其中 m - 没有。 of cases and n- features given (excluding x0)给定的案例和 n 个特征(不包括 x0)

We have y - > the label to predict -> matrix of (m,1)我们有 y -> 要预测的标签 -> (m,1) 的矩阵

Now while I'm implementing it from scratch in python, I'm confused as to why we use transpose of theta in the sigmoid function.现在,当我在 python 中从头开始实现它时,我很困惑为什么我们在 sigmoid 函数中使用 theta 的转置

在此处输入图片说明

Also we use theta transpose X for linear regression too.我们也使用theta 转置 X进行线性回归。

We do not have to perform matrix multiplication anywhere while coding, its straight element to element coding, what's the need for the transpose or is my understanding wrong and we need to take matrix multiplication during implementation.我们不必在编码时在任何地方执行矩阵乘法,它的直接元素到元素编码,转置的需要是什么,或者我的理解有误,我们需要在实现过程中进行矩阵乘法。

My main concern is that I'm very confused as to where we do matrix multiplication and where we do element wise multiplication in logistic and linear regression我主要担心的是,我很困惑我们在哪里进行矩阵乘法以及我们在哪里进行逻辑和线性回归中的元素乘法

You are a bit off topic for this area, but the piece you appear to be hung up on is the treatment of x and Theta .您对这个领域有点偏离主题,但您似乎被挂断的是xTheta的处理。

In the use cases you describe, x is a vector of inputs, or the "feature vector".在您描述的用例中, x是输入向量,或“特征向量”。 The Theta vector is the vector of coefficients. Theta向量是系数向量。 Both are usually expressed as column vectors and of course, must be of the same dimension.两者通常都表示为列向量,当然,必须具有相同的维度。

So to "make a prediction" you need the inner product of these two, and the output needs to be a scalar (by definition for inner product) so you need to transpose the theta vector in order to properly express that operation, which is a matrix multiplication of two vectors.因此,要“进行预测”,您需要这两者的内积,并且输出需要是标量(根据内积的定义),因此您需要转置theta向量以正确表达该操作,这是一个两个向量的矩阵乘法。 Make sense?有道理?

For matrix multiplication, the number of Columns in the first element must equal the number of rows in the second element .对于矩阵乘法,第一个元素中必须等于第二个元素中的行数 Since one of the elements your multiplying has either one column or one row, it does not appear to be matrix multiplication due to it's simplicity.由于您的乘法元素之一具有一列或一行,因此由于它的简单性,它似乎不是矩阵乘法。 But it still is matrix multiplication但它仍然是矩阵乘法

Let me provide an example,我举个例子,

Let A be (m,n) matrix We can perform scalar multiplication, for some fixed a in the real numbers If we want to multiply A to some vector, x , we need to meet some restrictions.A为 (m,n) 矩阵 我们可以进行标量乘法,对于实数中某个固定的a如果我们想将A与某个向量x相乘,我们需要满足一些限制。 Here it is common to mistake the dot product for matrix multiplication, but they serve completely different purposes.在这里,通常会将点积误认为矩阵乘法,但它们的用途完全不同。

So our restrictions for multiplying an (m,n) matrix, A by a vector x is that x has the same number of entries as A has columns To do this in your example, one of the elements needed to be transposed.因此,我们对 (m,n) 矩阵A乘以向量x是 x的条目数与 A 的列数相同。为此,在您的示例中,需要转置元素之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM