Class Prior
When you walk into a new problem with no features at all, you still have a “default guess” about what’s more likely. In classification, that default guess is captured by the class prior.
What a class prior is
A class prior is the probability of each class before looking at the input features: P(y). In a Naive Bayes classifier, you combine this with the likelihood of the features given the class, P(x | y), to get a posterior score for each class:
P(y | x) ∝ P(y) · P(x | y)
Intuitively, the prior is the model’s built-in “base rate.” If 95% of emails are not spam, the prior for “not spam” starts higher than “spam,” and the evidence from words in the email has to overcome that.
How it’s estimated in practice
Most commonly, P(y) is estimated from the training data as class frequency (often with smoothing to avoid zeros):
- Spam detection: prior reflects how common spam is in your labeled inbox.
- Fraud detection: prior is tiny because fraud is rare.
- Disease diagnosis: prior depends on prevalence in the screened population.
In scikit-learn’s Naive Bayes models (e.g., MultinomialNB), this shows up as class_prior (manual) or is learned from data via fit_prior.
Why it matters
Ignoring the right prior makes predictions systematically biased. If your training set is artificially balanced (50/50 fraud vs. not fraud) but real life is 1/1000, a learned prior from that data will wildly over-predict fraud. Setting or correcting the class prior is a clean way to align a probabilistic classifier with real-world base rates, especially under class imbalance or dataset shift.
Class prior is the probability distribution over class labels before observing any features, written as P(y). In supervised classification (including Naive Bayes), it represents the baseline prevalence of each class in the training population and is combined with the likelihood P(x|y) to compute posteriors P(y|x). It matters because misestimated priors bias predictions—especially under class imbalance—and proper priors improve calibration and decision thresholds.
Think of walking into a doctor’s office during flu season. Before hearing your symptoms, the doctor already knows flu is more common right now than, say, a rare disease. That “starting expectation” is like a class prior.
In AI classification (where a model picks a label like “spam” vs “not spam”), the class prior is the model’s best guess about how common each class is before looking at the details of a specific case. If 90% of emails are not spam, the model begins with that tilt. This matters when evidence is weak or noisy, helping predictions stay realistic.