Definition and interpretation of z in logistic regression

Prof Ng defines z as z = w.x + b; however he doesn’t give the interpretation of this variable z.
In linear regression it is pretty intuitive that we are taking a training example as an input and projecting it’s output on a graph using our pre-defined linear/polynomial regression model ( f(x) =w.x + b ).
In logistic regression, I don’t understand what z is, intuitively and graphically. z is in fact a scalar, but does this scalar represent ?
Thanks in advance.

Hello @renesultan

Welcome to the community.

Here is the reference to an article that explains what “z” is. Do let me know if this gives you the clarity.

I think he did explain Z’s intuition with respect to logistic regression when he was explaining decision boundaries. The line drawn using Z acts as the decision boundary. If Z is linear, you will have linear decision boundary and if it contains power of x, you will get non linear decision boundary.

The sigmoid function of Z becomes greater than 0.5 if Z is >=0. So, if you use a threshold 0.5 to separate classes, it will mean whatever is on positive side of line defined by Z is one class and the other class is one opposite side.

Great sharing! @shanup presented the convenience of having z in calculus; @Shivanshu_Singh told us Professor Andrew Ng’s geometric interpretation of the polynomial function z as a decision boundary (course 1 week 3 Video: Decision Boundary, and a relevant discussion); my last point is, mathematically, z is also called a logits in our context (logistic regression), so your wx+b projects x to logits z and your sigmoid function projects z to a probability. logits is a name you will see again in course 2 week 2.

Following on from this point, and from the conversation referred to in @shanup’s post, I am unclear whether z is a scalar or a vector/array.
As z = (dot product of w and x) + b, I would have thought this would produce a scalar as @renesultan states. However, in the final C1 W3 Logistic Regression Programming Assignment, it states (in relation to z in the Sigmoid function):


Note that

  • z is not always a single number, but can also be an array of numbers.
  • If the input is an array of numbers, we’d like to apply the sigmoid function to each value in the input array.


Please could you clarify?


Hello Jem,

If we have one sample, then we have one z and z is a scalar.

If we have two samples, then we have two z and z is a vector/array.

For example,

import numpy as np

x = np.array([
    [1., 2., 3., ], # sample 1
    [3., 4., 5., ], # sample 2

w = np.array([
    [6., ],
    [7., ],
    [8., ],

sigmoid = lambda z: 1/(1+np.exp(-z))

z = x @ w
a = sigmoid(z)


Both z and a are arrays.


Great, thanks Raymond.