Optional lab 02: Sigmoid function and logistic regression


In the lab, it says the following:

  • In the case of a single example, z is scalar.
  • in the case of multiple examples, z may be a vector consisting of m values, one for each example.

This is quite new. For our linear regression model, we’ve passed in multiple features, but never multiple examples. Am I understanding this right in that the logistic model should be able to take in multiple examples to produce multiple outputs, or is this a typo and it’s supposed to say features? Thanks!

Amr Ojjeh

This is simply a difference of implementation. Earlier examples used for-loops to iterate through the examples. But that’s not strictly necessary - you can instead use matrix algebra to multiply (using a matrix product) by all of the examples (arranged as a matrix) in one operation.

The results are identical, but using a matrix product is more efficient because numpy is designed for exactly that purpose.

1 Like

Gotcha. I understood its implications, but I just wasn’t sure if it was intentional. I think it may help to clarify that point explicitly in the lab, as that’s not how it was previously done. Thank you for your elaboration!