Two useful goals, not two competing buzzwords
A discriminative model learns the rule needed to predict a target from an observed input. A generative model learns enough about how data occurs to represent or create possible samples. The best choice depends on the job: deciding, estimating, creating, filling missing information, or combining several of those tasks.
Discriminative does not mean “classification only.” A discriminative regression model can map a house description to a continuous price. Generative does not mean “images only.” A generator may produce text, audio, rows, sequences, or other data.
Generative vs Discriminative in Simple Words
Think of a detective vs an artist: A discriminative model acts like a detective—given a handwritten note (x), it determines whether it belongs to Suspect A or Suspect B ($P(y|x)$). A generative model acts like a master artist—it studies Suspect A’s handwriting style so thoroughly that it can forge brand-new sentences in that exact style ($P(x|y)$)!
Discriminative: P(y | x)
Learns the decision boundary between classes. High predictive accuracy, but cannot sample new data points.
Generative: P(x, y) = P(x | y)P(y)
Learns the full joint probability distribution. Can synthesize realistic samples, handle missing features, and detect out-of-distribution inputs.
Read the probability notation one piece at a time
x — the input or observed data
Example: whether an email contains the word “offer,” plus its other measured features.
y — the target
Example: spam or legitimate. For regression, y could instead be a number such as price.
p(y | x) — target given input
After observing x, how likely is each y? This is the usual discriminative direction.
p(x) and p(x, y) — data and joint patterns
p(x) describes inputs. p(x, y) describes inputs and targets occurring together.
p(x | y) — input given a target
Within a chosen class y, how likely is an input pattern x? A class-conditional generator can use this direction to create an example belonging to y.
Figure 1 — Two learning pathways through the same two classes
Circles and squares mean the same classes on both sides. The discriminative path learns the boundary needed to predict y from x; the generative path learns where each class tends to occur, which supports sampling a new x or comparing p(x | y) values for classification.
A paired diagram uses blue circles and amber squares for the same two classes. The discriminative side draws a visible decision boundary and continues to p of y given x and a predicted class. The generative side draws two class distributions, samples a new x, and also shows that an observed x can be classified by comparing p of x given each y.
DISCRIMINATIVE · LEARN TO SEPARATE
GENERATIVE · LEARN HOW DATA OCCURS
Read this as “the probability of target y after input x is known.” A spam detector can estimate this quantity directly without modelling every possible way an email might be written.
p(y) is the prior frequency of a class. p(x | y) describes the input inside that class. p(x) makes the probabilities normalize correctly. A generative classifier can learn these quantities and then calculate p(y | x). Modern generators may instead learn an implicit sampling process and never expose a tractable numerical likelihood.
Worked example: the word “offer” in 100 emails
The following counts are observed data, not model outputs. Let x mean “the email contains offer,” and let y mean “the email is spam.”
| Observed class | Contains “offer” | Does not contain “offer” | Row total |
|---|---|---|---|
| Spam | 30 | 10 | 40 |
| Legitimate | 6 | 54 | 60 |
| Column total | 36 | 64 | 100 |
Figure 2 — Joint, marginal, and conditional probabilities in the same count grid
A joint probability uses one cell, a marginal probability totals across a row or column, and a conditional probability renormalizes only inside the chosen condition. The values match the 100-email worked example below.
A two by two count grid has spam rows of 30 offer and 10 no offer, legitimate rows of 6 offer and 54 no offer, row totals 40 and 60, column totals 36 and 64, and grand total 100. The joint spam and offer cell is 30. The offer marginal is 36, the spam marginal is 40, and within the spam row p of offer given spam is 30 divided by 40 or 0.75.
1. p(x) = 36 / 100 = 0.36
Thirty spam plus six legitimate emails contain “offer,” so 36 of 100 observed inputs have x.
2. p(y) = 40 / 100 = 0.40
Forty of the 100 emails are spam, so the prior probability of spam is 0.40.
3. p(x, y) = 30 / 100 = 0.30
Thirty emails are both spam and contain “offer.” This is a joint probability.
4. p(x | y) = 30 / 40 = 0.75
Among the 40 spam emails, 30 contain “offer.” This describes x inside the spam class.
5. p(y | x) = 30 / 36 = 0.833
Among the 36 emails containing “offer,” 30 are spam. The discriminative prediction is therefore about 83.3% spam for this one-feature example.
A discriminative model may learn the final 83.3% mapping directly. A simple generative classifier may learn class frequencies and within-class word patterns, then reach the same conditional result using Bayes’ rule. A content generator would need far richer patterns than this one-word table.
Reproduce every probability
This self-contained Python calculation uses only the four counts shown in the table. Each division matches one numbered step above.
total = 100
spam = 40
offer = 36
spam_and_offer = 30
p_x = offer / total
p_y = spam / total
p_x_and_y = spam_and_offer / total
p_x_given_y = spam_and_offer / spam
p_y_given_x = spam_and_offer / offer
print(p_x, p_y, p_x_and_y, p_x_given_y, p_y_given_x)
# 0.36 0.40 0.30 0.75 0.8333333333333334Discriminative Boundary vs Generative Distribution Contours
Discriminative draws one dividing line; Generative models the complete density cloud for each class.
Comparison and decision guide
| Question | Discriminative modelling | Generative modelling |
|---|---|---|
| Primary job | Predict y from observed x | Represent or sample possible x values, optionally conditioned on y or other information |
| Typical output | Class, probability, score, or continuous value | A new sample, reconstruction, completion, or sometimes a class prediction |
| When it is enough | The product only needs an accurate decision or numeric estimate | Not necessary merely because the data is complex |
| What it adds | Often simpler and more directly optimized for prediction | Creation, simulation, missing-data modelling, representation learning, or multiple downstream uses |
| Important caveat | May not explain how inputs themselves occur | Can be harder to train and evaluate; not every model has an explicit likelihood |
Summary / Key Takeaways
- A discriminative model directly learns the prediction direction p(y | x): the target after the input is known.
- A generative model represents how data occurs through quantities such as p(x), p(x, y), or p(x | y), or through an implicit sampling process.
- Discriminative models can output continuous values as well as classes, and generative models can also support classification.
- In the email example, 30 of the 36 messages containing ‘offer’ are spam, so p(spam | offer) = 30 / 36 ≈ 0.833.
- Use discriminative modelling when the real requirement is an accurate label, score, or numerical estimate.
- Choose generative modelling when creation, simulation, missing-data modelling, representation learning, or sampling the data process adds useful value.