Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Perceptron vs. Logistic Regression: A GLM Perspective

Welcome to the first lesson of your course, "AI from Sequence to Sequence." Your goal is to build a robust theoretical foundation for modern AI, starting from the precursors to today's complex models. Given your proficiency in classical machine learning, our journey begins by reframing concepts you're already familiar with—specifically, logistic regression and the perceptron—as the fundamental building blocks of neural networks.

In this lesson, we will compare the perceptron and logistic regression models, formalizing their relationship through the powerful framework of Generalized Linear Models (GLMs). This will not only provide a deeper, more unified perspective on these algorithms but also establish the core "neuron" abstraction that we will build upon throughout this course, from simple networks to the advanced transformer architectures at the frontier of AI.

From Linear Models to a Neuron

You're already familiar with linear and logistic regression. Both models compute a weighted sum of the input features, often written as a dot product plus a bias: . This term, , is the linear predictor or net input.

The key difference between these models lies in what they do after computing this linear predictor.

  • Linear Regression uses this value directly as its output, aiming to predict a continuous target.
  • Logistic Regression passes this value through a sigmoid (or logistic) function, , to squash the output into the range , interpreting it as a probability.
  • The Perceptron, one of the earliest models of a neuron, takes a simpler approach: it passes the linear predictor through a threshold (or Heaviside step) function. If the input is positive, it outputs 1; otherwise, it outputs 0.

So, all three models share a common core: a linear transformation. The difference is the activation function applied to the result. For linear regression it's the identity function (), for logistic regression it's the sigmoid function, and for the perceptron it's the step function.

To formalize this comparison, let's turn to the Andrew Ng's CS229 lecture notes, which you'll find a useful reference throughout our early lessons.

[PDF] CS229 Lecture notes - DataJobs.com

This reading introduces the perceptron learning algorithm by directly contrasting it with logistic regression.

In the document, please read the short section titled "Digression: The perceptron learning algorithm" (page 20). Notice how the perceptron is presented as a modification of logistic regression where the sigmoid function is replaced by a "forced" threshold function.

This simple change—from a smooth sigmoid to a hard threshold—has significant implications. As the notes mention, it becomes difficult to assign a meaningful probabilistic interpretation to the perceptron's output. Logistic regression, on the other hand, has a very elegant probabilistic foundation, which is best understood through the lens of Generalized Linear Models.

A Unifying Framework: Generalized Linear Models (GLMs)

Generalized Linear Models provide a framework that unifies various regression models, including linear and logistic regression. Understanding GLMs will make it clear why the sigmoid function isn't just an arbitrary choice for logistic regression but rather a natural consequence of its underlying statistical assumptions.

A GLM is defined by three components:

  1. Random Component: Specifies the probability distribution of the response variable , given the features . This distribution must be a member of the exponential family (e.g., Normal, Bernoulli, Poisson).
  2. Systematic Component: A linear predictor, which is a linear combination of the input features: .
  3. Link Function: A function that connects the expected value of the random component, , to the systematic component: . The inverse of the link function, , is called the response function.
This diagram summarizes the three core components of a GLM and lists several common types, including Linear and Logistic Regression, along with their associated link functions.

The following reading from Andrew Ng's notes provides the theoretical backbone for GLMs, showing how common distributions fit into the exponential family and laying out the three assumptions for constructing a GLM. Your strong math background will be an asset here.

[PDF] CS229 Lecture notes - DataJobs.com

This material introduces the exponential family of distributions and defines the three core assumptions used to construct any GLM.

Please read Part III, "Generalized Linear Models," starting from the beginning of Section 8 up to the end of Section 9 (pages 22-25). Pay close attention to: The definition of the exponential family form: p(y; \eta) = b(y) \exp(\eta^T T(y) - a(\eta)). How the Bernoulli and Gaussian distributions are shown to be members of this family. The three assumptions for building a GLM at the beginning of Section 9.

Deriving Logistic Regression as a GLM

With the GLM framework established, we can now derive logistic regression from first principles. This derivation is a perfect example of the kind of theoretical intuition this course aims to build.

We follow the three GLM assumptions:

  1. Random Component: For binary classification, the outcome is either 0 or 1. The natural distribution to model this is the Bernoulli distribution. So, we assume , where .
  2. Systematic Component: We assume a linear relationship between the parameters and the features: .
  3. Link Function: Our goal is to predict the expected value of . For a Bernoulli distribution, the expectation is simply the probability of success: . The canonical link function for the Bernoulli distribution is the logit function, which you saw in the derivation showing Bernoulli is in the exponential family: This term, the log of the odds, is the logit.

Now, by setting the link function equal to the systematic component, we get:

To find our hypothesis , we simply solve for :

And there it is: the sigmoid function emerges not as an ad-hoc choice, but as the canonical response function when modeling a Bernoulli-distributed outcome within the GLM framework.

The following brief reading confirms this derivation.

[PDF] CS229 Lecture notes - DataJobs.com

This short section provides a concise summary of the derivation we just walked through.

Please read Section 9.2, "Logistic Regression" (page 26). This reinforces how the choice of a Bernoulli distribution for the response variable naturally leads to the sigmoid hypothesis function.

From GLMs to Neural Network Units

We can now see logistic regression and the perceptron as two variations on a single theme. They are both simple computational "units" that take an input vector , compute a linear combination , and apply an activation function.

  • Logistic Regression Unit:
  • Perceptron Unit:

This structure—a linear transformation followed by a non-linear activation—is the fundamental building block of a neural network. A single logistic regression classifier is a neural network with a single neuron, an input layer, and a sigmoid activation function.

The following reading and video provide a clear summary of this perspective, placing linear and logistic regression within the GLM framework and viewing them as simple neural networks.

[PDF] Multiclass Logistic Regression, Multilayer Perceptron

This resource formalizes the GLM structure and presents a helpful comparison table.

On page 6, read the section "Generalized Linear Models". Focus on the formulation y(\mathbf{x}; \mathbf{w}, b) = a(\mathbf{w}^T\mathbf{x} + b) and the accompanying table, which neatly summarizes the components for both linear and logistic regression.

L5.2 Relation Between Perceptron and Linear Regression

This short video by Sebastian Raschka provides a clear, conceptual walkthrough comparing the perceptron and linear regression, framing them both as single-neuron models.

Please watch from the beginning until the end. The key idea is visualizing linear regression as having an "identity" activation function, which makes the comparison to the perceptron's threshold activation very direct.

By reframing what you know about linear models in this way, you've already taken the first crucial step. You now understand the basic computational unit that, when scaled up and composed in layers, forms the powerful deep learning models we will be studying.

Conclusion

In this lesson, we established a crucial bridge between classical machine learning and neural networks.

Key Takeaways:

  • The Perceptron and Logistic Regression models both consist of a linear transformation of inputs () followed by an activation function.
  • The Perceptron uses a non-probabilistic threshold (step) function, while Logistic Regression uses a smooth sigmoid function.
  • The Generalized Linear Model (GLM) framework explains why logistic regression uses the sigmoid function. It is the natural result of assuming a Bernoulli distributed outcome and using the canonical logit link function.
  • This "linear combination + activation function" structure defines a single neuron, the fundamental building block of neural networks. A logistic regression classifier can be viewed as a single-neuron neural network.

This perspective reveals that the foundations of deep learning are rooted in well-established statistical principles. However, the power of neural networks comes not from a single neuron, but from combining them. A single neuron, like logistic regression, can only learn a linear decision boundary. In our next lesson, we will investigate the limitations of this by exploring the classic XOR problem, which a single neuron cannot solve. We will then see how stacking these neurons into a Multi-Layer Perceptron (MLP) overcomes this limitation and unlocks the ability to learn complex, non-linear functions.

Can't find a good explanation? Sign up and we'll make it for you

Sign up