1. Explore the sigmoid function (also known as the logistic function)
  2. Explore logistic regression; which uses the sigmoid function

Sigmoid or Logistic function:

Logistic regression used a special function called the sigmoid. It looks like an S-shaped curve.

Screenshot 2025-02-10 at 11.34.33 AM.png

For a classification task, we can start by using the linear regression model to predict y given x.

$$ f_{\mathbf{w},b}(\mathbf{x}^{(i)}) = \mathbf{w} \cdot  \mathbf{x}^{(i)} + b $$

Let's implement the sigmoid function and see this for ourselves.

Formula for Sigmoid function:

The formula for a sigmoid function is as follows -

$$ g(z) = \frac{1}{1+e^{-z}}\tag{1} $$

In the case of logistic regression, z (the input to the sigmoid function), is the output of a linear regression model.

NumPy has a function called exp(), which offers a convenient way to calculate the exponential e^z of all elements in the input array (z).

It also works with a single number as an input, as shown below.

# Input is an array. 
input_array = np.array([1,2,3])
exp_array = np.exp(input_array)

print("Input to exp:", input_array)
print("Output of exp:", exp_array)

# Input is a single number
input_val = 1  
exp_val = np.exp(input_val)

print("Input to exp:", input_val)
print("Output of exp:", exp_val)