Plot the decision boundary for a logistic regression model.

This will give us a better sense of what the model is predicting.

import numpy as np
import matplotlib.pyplot as plt
from lab_utils_common import plot_data, sigmoid, draw_vthresh

Dataset:

Let's suppose we have following training dataset

X = np.array([[0.5, 1.5], [1,1], [1.5, 0.5], [3, 0.5], [2, 2], [1, 2.5]])
y = np.array([0, 0, 0, 1, 1, 1]).reshape(-1,1) 

Plot data:

Let's use a helper function to plot this data. The data points with label 𝑦=1 are shown as red crosses, while the data points with label 𝑦=0 are shown as blue circles.

fig,ax = plt.subplots(1,1,figsize=(4,4))
plot_data(X, y, ax)

ax.axis([0, 4, 0, 3.5])
ax.set_ylabel('$x_1$')
ax.set_xlabel('$x_0$')
plt.show()

Screenshot 2025-02-12 at 2.44.21 PM.png

Logistic regression model:

Suppose we'd like to train a logistic regression model on this data which has the form

$$ f(x) = g(w_0x_0+w_1x_1 + b) $$

where

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

which is the sigmoid function

Let's say that we trained the model and get the parameters as b = -3, w_0 = 1, w_1 = 1. That is,

$$ f(x) = g(x_0+x_1-3) $$