Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Logistic Regression Classifier Lab

Place points for two classes, then train a logistic regression classifier and watch the straight decision boundary rotate into place as the cross-entropy loss drops and accuracy climbs. Compare separable, overlapping, diagonal, and XOR data to see where a single linear boundary works and where it fails.

Guided Experiment: Train a classifier on separable data

If two classes form two clearly separated clusters, do you expect logistic regression to classify every point correctly? Predict what the decision boundary will look like.

Write your hypothesis in the Lab Report panel, then click Next.

Classifier Plot

02468100246810feature x₁feature x₂Class A (1.5, 2.0)Class A (2.3, 1.4)Class A (1.0, 3.1)Class A (2.8, 2.6)Class A (1.9, 1.0)Class A (3.2, 1.8)Class A (2.1, 3.4)Class B (7.4, 8.1)Class B (8.2, 7.3)Class B (6.9, 8.8)Class B (8.6, 8.4)Class B (7.7, 6.9)Class B (9.0, 7.7)Class B (7.1, 7.5)
Class A (label 0)Class B (label 1)

Click empty space to add a point of the selected brush class. Drag a point to move it. Shift+click a point to remove it.

Training Metrics

Epoch
0 / 300
Loss
n/a
Accuracy
n/a
w₁
0.000
w₂
0.000
b
0.000
Cross-entropy lossAccuracy
1.00epochRun to plot the loss curve
What the run shows
  • The boundary is a straight line because logistic regression is a linear classifier.
  • Press Run Experiment to train and watch the boundary move.

Controls

Data Table

(0 rows)
#DatasetLearning rateEpochsFinal lossAccuracy
0 / 500
0 / 500
0 / 500

Reference Guide

What Logistic Regression Does

Logistic regression turns a linear score into a probability using the sigmoid function. The score is a weighted sum of the features.

p=σ(w1x1+w2x2+b)=11+e(w1x1+w2x2+b)p = \sigma(w_1 x_1 + w_2 x_2 + b) = \frac{1}{1 + e^{-(w_1 x_1 + w_2 x_2 + b)}}

A point is assigned to Class B when the predicted probability is at least 0.5, and to Class A otherwise.

The Decision Boundary Is a Line

The 0.5 threshold happens exactly where the linear score equals zero. In two dimensions that set is a straight line.

w1x1+w2x2+b=0w_1 x_1 + w_2 x_2 + b = 0

Because the boundary is always linear, logistic regression can only split data that two regions of one straight line can separate.

Cross-Entropy Loss and Gradient Descent

Training minimizes the mean binary cross-entropy, which is small when correct points get high probability.

L=1ni=1n[yilnpi+(1yi)ln(1pi)]L = -\frac{1}{n}\sum_{i=1}^{n} \left[ y_i \ln p_i + (1 - y_i)\ln(1 - p_i) \right]

Each epoch moves the weights a small step against the gradient. The learning rate sets the step size, so a larger rate converges faster but can overshoot.

Linear Separability and the XOR Limit

Data is linearly separable when one straight line can put every point of each class on its own side.

  • Separable clusters reach 100 percent accuracy.
  • Overlapping classes leave some points misclassified.
  • XOR places each class in two opposite corners, so no single line can separate it and accuracy stalls near 50 percent.

Solving XOR needs a nonlinear model such as a neural network with a hidden layer.

Related Content