AI Computer Institute
Expert-curated CS & AI curriculum aligned to CBSE standards. A bharath.ai initiative. About Us

Probability and Statistics for AI

📚 Mathematics & Data Science⏱️ 20 min read🎓 Grade 11
✍️ AI Computer Institute Editorial Team Updated: August 2026 CBSE-aligned · Peer-reviewed · 20 min read
Content curated by subject matter experts with IIT/NIT backgrounds. All chapters are fact-checked against official CBSE/NCERT syllabi.

Meera sends ₹500 to her brother Arjun on PhonePe — a transfer she has made a dozen times before. This time the app freezes on "Processing," then declares the transaction blocked pending verification: "This transaction looks unusual. Please verify your identity." Meera is annoyed. Arjun is the same person, the same UPI ID, the same amount range as always. Her bank later tells her, almost proudly, that its fraud-detection model is "99% accurate." If it is so accurate, why did it just get her transaction wrong?

The honest answer is that it probably did not get anything "wrong" at all — it did exactly what the mathematics of probability predicts it will do. By the end of this chapter you will be able to prove, with a short calculation, that a fraud detector can be 99% accurate in a very specific technical sense and still be wrong most of the time it raises an alarm. That slightly uncomfortable fact is also one of the most important ideas in artificial intelligence: every AI system you will ever build — a spam filter, a medical-scan classifier, a self-driving car's pedestrian detector, a language model choosing its next word — is, underneath its code, a machine for producing and reasoning about probabilities. Probability is the mathematics of uncertainty, and statistics is the toolkit for turning raw data into estimates of that uncertainty. Together they are the language AI is written in.

What Probability Actually Measures

Every probability problem starts with an experiment: a process whose outcome is uncertain in advance — flipping a coin, drawing a card, or checking whether a single UPI transaction turns out to be fraudulent. The set of every possible outcome of an experiment is called the sample space, written Ω. For a single transaction we can simplify the sample space to two outcomes: Ω = {Fraud, Not Fraud}. Any subset of the sample space is called an event. "The transaction is fraudulent" is an event; so is "the transaction is legitimate."

A valid probability assignment must satisfy three rules, known as the axioms of probability: every event's probability lies between 0 and 1; the probability of the entire sample space is 1, since something in Ω always happens; and for two events that cannot happen together (mutually exclusive events), the probability that either one happens is the sum of their individual probabilities. In symbols: 0 ≤ P(A) ≤ 1, P(Ω) = 1, and P(A ∪ B) = P(A) + P(B) whenever A and B cannot both occur.

Where do the actual numbers come from? In practice, AI systems estimate probability empirically, from data: P(A) ≈ (number of times A occurred) / (total number of trials observed). Suppose a payments company studied a large batch of its historical transactions, each one later confirmed by investigators as fraudulent or genuine, and found that 1 in every 1,000 was fraud. That gives an estimate P(Fraud) = 0.001. This number — the probability of an event before you look at any new evidence — is called the base rate, or the prior probability. It turns out to be the single most important number in Meera's story.

Conditional Probability: Updating Beliefs with Evidence

A fraud-detection model does not just guess P(Fraud) blindly — it looks at evidence (transaction amount, location, time of day, device) and revises its estimate. This revised, evidence-informed probability is called conditional probability, written P(A|B): "the probability of A, given that B has happened." It is defined as:

P(A|B) = P(A ∩ B) / P(B),   where P(B) > 0

Read the numerator as "the probability that both A and B happen," and the denominator as "the probability that B happens at all." Conditioning on B shrinks the sample space down to just the outcomes where B is true, and asks what fraction of that smaller space also satisfies A.

Now suppose the fraud model raises a flag — call this event Flag. Two conditional probabilities describe how good the model is at its job:

  • P(Flag | Fraud): the probability the model flags a transaction, given that it really is fraud. This is called the model's sensitivity (or recall). A good model pushes this close to 1.
  • P(Flag | Not Fraud): the probability the model flags a transaction that is actually legitimate — a false-positive rate. A good model pushes this close to 0.

But Meera does not care about either of these numbers. She wants to know P(Fraud | Flag): given that the model flagged her transaction, what is the probability it is actually fraud? That is the reverse conditional probability, and reversing a conditional probability requires a specific tool: Bayes' theorem.

P(A|B) = P(B|A) · P(A) / P(B)

Bayes' theorem follows directly from the definition of conditional probability: P(A∩B) = P(A|B)·P(B) = P(B|A)·P(A), so dividing through by P(B) gives the formula above. In the language every machine learning course uses, P(A) is the prior (what you believed before seeing evidence), P(B|A) is the likelihood (how well the evidence fits that belief), and P(A|B) is the posterior (your updated belief after seeing the evidence). This one-line formula for updating beliefs under new evidence is the mathematical foundation of Bayesian machine learning, spam filters, and medical-test interpretation alike.

Worked Example: How Suspicious Is a "Suspicious" Transaction?

Let's give the fraud model concrete, if illustrative, numbers and trace the calculation completely. Suppose:

  • P(Fraud) = 0.001 — the base rate, 1 fraudulent transaction in every 1,000.
  • P(Flag | Fraud) = 0.99 — the model catches 99% of real fraud.
  • P(Flag | Not Fraud) = 0.01 — the model wrongly flags only 1% of legitimate transactions.

Both 99%-level figures sound excellent — exactly the kind of number Meera's bank would advertise. We want P(Fraud | Flag). By Bayes' theorem:

P(Fraud|Flag) = P(Flag|Fraud) · P(Fraud)
                ─────────────────────────────────────────────
                P(Flag|Fraud)·P(Fraud) + P(Flag|¬Fraud)·P(¬Fraud)

              = (0.99 × 0.001) / (0.99 × 0.001 + 0.01 × 0.999)
              = 0.00099 / (0.00099 + 0.00999)
              = 0.00099 / 0.01098
              ≈ 0.0902

Only about 9%. Despite two 99%-level accuracy figures, roughly 91 out of every 100 flagged transactions are completely innocent. It helps to see this with actual transaction counts instead of fractions. Imagine 100,000 transactions pass through the system in a day:

  • Expected fraud cases: 100,000 × 0.001 = 100. Expected legitimate cases: 99,900.
  • Of the 100 fraud cases, the model correctly flags 0.99 × 100 = 99 of them — true positives.
  • Of the 99,900 legitimate cases, the model wrongly flags 0.01 × 99,900 = 999 of them — false positives.
  • Total transactions flagged: 99 + 999 = 1,098.
  • Fraction of flags that are real fraud: 99 / 1,098 ≈ 9.02% — matching the algebra exactly.

This is not a quirk of these particular numbers; it is a general phenomenon called the base-rate fallacy: whenever the event you are detecting is rare, even a highly accurate detector produces mostly false alarms among its positive flags, because the enormous pool of true negatives supplies far more false positives (999) than the tiny pool of true positives (99) can compete with. The same arithmetic explains why a highly accurate medical test for a rare disease still leaves most positive results as false alarms, and why email spam filters are tuned to keep false-positive rates extremely low — a "spam" label wrongly placed on your college admission email is far more costly than one spam message reaching your inbox.

You can confirm this with a direct simulation instead of algebra. The following program generates a million simulated transactions using exactly the three probabilities above, and counts what actually happens:

import random

random.seed(42)
N = 1_000_000          # simulate one million transactions
flagged_count = 0
correctly_flagged = 0

for _ in range(N):
    is_fraud = random.random() < 0.001         # true fraud rate
    if is_fraud:
        flagged = random.random() < 0.99        # 99% sensitivity
    else:
        flagged = random.random() < 0.01         # 1% false-positive rate
    if flagged:
        flagged_count += 1
        if is_fraud:
            correctly_flagged += 1

print(f"Transactions flagged: {flagged_count}")
print(f"Of those, actually fraud: {correctly_flagged}")
print(f"P(Fraud | Flagged) = {correctly_flagged / flagged_count:.4f}")

Running this exact code produces:

Transactions flagged: 10969
Of those, actually fraud: 935
P(Fraud | Flagged) = 0.0852

The simulated posterior (8.5%) lands close to the algebraic answer (9.0%) — the small gap is ordinary sampling noise, since only around 1,000 of the million simulated transactions were fraud to begin with, and rare-event counts fluctuate from run to run. Change the seed or increase N further and the number keeps settling in the same neighbourhood, never anywhere near 99%. That gap between "the model's accuracy" and "the probability my flagged transaction is really fraud" is precisely why a bank almost never blocks a card purely on one model's flag — it treats the flag as one more piece of evidence and combines it with transaction history, device, and location to keep updating the posterior before deciding.

Random Variables and Probability Distributions

To move from single events to the kind of data AI models actually train on, we need a random variable: a rule that assigns a number to every outcome of an experiment. For a discrete random variable — one that takes a countable set of values — we describe its behaviour with a probability mass function (PMF), P(X = k), giving the probability of each possible value.

Consider X = the number of boundaries (fours and sixes) a batsman hits in a six-ball over. If, purely for illustration, we assume an independent 20% chance of a boundary off any given ball (a simplification — real cricket has momentum and field-placement effects that break independence), then X follows a Binomial distribution with parameters n = 6 and p = 0.2, and:

P(X = k) = C(n, k) · p^k · (1-p)^(n-k)

where C(n, k) = n! / (k!(n−k)!) counts the number of ways to choose which k of the 6 balls are boundaries. For exactly 2 boundaries in the over:

C(6,2) = 15
p^2 = 0.2^2 = 0.04
(1-p)^4 = 0.8^4 = 0.4096

P(X=2) = 15 × 0.04 × 0.4096 = 0.24576 ≈ 24.6%

A continuous random variable, by contrast, takes values from an unbroken range (like a transaction amount in rupees, which can be ₹499.50 or ₹499.51), and is described by a probability density function (PDF) instead of a PMF — probability is read off as the area under the curve over an interval, not the height at a single point, because any single exact value has probability zero. The single most important continuous distribution in AI is the Normal (Gaussian) distribution, the familiar bell curve, fully described by just two numbers: its mean μ and standard deviation σ. Its importance comes from the Central Limit Theorem, which states that when you add up many independent random quantities, their sum tends toward a Normal distribution regardless of the shape of the original quantities. This is why measurement noise, aggregated user behaviour, and the weight initializations used to start training a neural network are so often modelled as Gaussian.

Descriptive Statistics: Mean, Variance, and Why AI Needs Them

Where probability theory reasons forward from assumed models to predicted outcomes, statistics reasons backward from observed data to estimate the underlying numbers. The two most basic statistics are the mean (the average, a measure of central tendency) and the variance (a measure of spread):

mean:      μ = (1/n) · Σ xᵢ
variance:  σ² = (1/n) · Σ (xᵢ − μ)²
std dev:   σ = √(σ²)

Standard deviation is simply the square root of variance, expressed in the same units as the original data (rupees, rather than rupees-squared), which makes it easier to interpret. Consider five UPI transaction amounts in rupees: 200, 450, 500, 5000, 300.

mean = (200+450+500+5000+300) / 5 = 6450 / 5 = 1290

deviations from mean: -1090, -840, -790, 3710, -990
squared deviations:   1,188,100  705,600  624,100  13,764,100  980,100

variance = 17,262,000 / 5 = 3,452,400
std dev  = √3,452,400 ≈ 1858.1

Notice how the mean, ₹1,290, is larger than four of the five actual amounts — a single outlier (₹5,000) has pulled it upward, and has an even more dramatic effect on the variance, since squaring a large deviation (3710² = 13,764,100) makes it dwarf the other four squared deviations combined. This sensitivity to outliers is exactly why financial AI systems often work with the logarithm of transaction amount rather than the raw rupee value, and it is also the basis of a simple anomaly-detection technique: the z-score, z = (x − μ)/σ, measuring how many standard deviations a point sits from the mean. For the ₹5,000 transaction:

z = (5000 − 1290) / 1858.1 = 3710 / 1858.1 ≈ 2.0

A transaction sitting about two standard deviations above the mean is unusual enough that a simple statistical rule — flag anything with |z| > 2 — would catch it without any machine learning at all. This is precisely why standardization (also called feature scaling) is one of the first steps in almost every AI pipeline: transforming every input feature to have mean 0 and standard deviation 1 puts features measured on wildly different scales (transaction amount in thousands of rupees, time-of-day in hours 0–23, account age in days) onto comparable footing, which helps gradient-based optimizers like gradient descent converge faster and stops large-magnitude features from dominating a model simply because of their units.

Probability Inside Real AI Systems

The concepts above are not separate from machine learning — they are its internal machinery. Three examples make this concrete.

Naive Bayes classifiers apply Bayes' theorem directly to classification. To decide whether a message is spam, the model estimates P(spam | words) using P(words | spam) · P(spam), assuming — naively, hence the name — that each word contributes independently to the evidence. Despite that unrealistic independence assumption, Naive Bayes remains a fast, effective baseline for text classification:

from sklearn.naive_bayes import MultinomialNB
from sklearn.feature_extraction.text import CountVectorizer

texts = ["win a free recharge now", "meeting at 5pm tomorrow",
         "claim your prize instantly", "project deadline reminder"]
labels = ["spam", "ham", "spam", "ham"]

vectorizer = CountVectorizer()
X = vectorizer.fit_transform(texts)

model = MultinomialNB()
model.fit(X, labels)

new_message = vectorizer.transform(["claim your free prize"])
print(model.predict(new_message))          # ['spam']
print(model.classes_)                      # ['ham' 'spam']
print(model.predict_proba(new_message))    # [[0.0695, 0.9305]]

The model does not just output a label — predict_proba returns the actual posterior probability distribution, 93.05% spam and 6.95% ham, the same quantity Bayes' theorem computed by hand for Meera's transaction.

Softmax is how neural networks manufacture probability distributions out of raw numeric outputs. A classification network's last layer produces one real number per class, called a logit, which can be any positive or negative value. Softmax converts a vector of logits z into a valid probability distribution:

softmax(zᵢ) = e^zᵢ / Σⱼ e^zⱼ

For logits [2.0, 1.0, 0.1] — perhaps a network's raw scores for classes "cat," "dog," "bird":

e^2.0 ≈ 7.389,  e^1.0 ≈ 2.718,  e^0.1 ≈ 1.105
sum ≈ 11.213

softmax ≈ [7.389/11.213, 2.718/11.213, 1.105/11.213]
        ≈ [0.659, 0.242, 0.099]

The three outputs are all positive and sum to exactly 1 — a genuine probability distribution over "cat," "dog," and "bird," with "cat" the most likely class at 65.9%. Training then uses cross-entropy loss, L = −Σ yᵢ log(pᵢ), which measures how far this predicted distribution is from the true one-hot label and pushes the network's logits toward the correct class with every gradient update. Many image classifiers, next-word predictions inside language models, and recommendation rankings ultimately end their forward pass at a softmax layer, outputting not a single guess but a full distribution over possibilities.

Back to Meera's Blocked Transaction

Meera's payment was not the victim of a broken model — it was an entirely predictable consequence of a rare event (fraud, at a 0.1% base rate) being tested against a common one (legitimate transfers, 99.9% of traffic). No single accuracy figure fixes that; what actually helps is exactly what real fraud systems do — treat the flag as a likelihood, not a verdict, and combine it with more evidence (Arjun's UPI ID appearing repeatedly in Meera's transaction history, her phone's usual location, the familiar time of day) to keep applying Bayes' theorem, pushing the posterior probability back down until the system is confident enough to let the payment through automatically, or confident enough in the other direction to ask for one extra confirmation — exactly as happened to Meera.

The practical takeaway for any AI system you build or evaluate: never accept a single "accuracy" number at face value. Ask what the base rate of the event actually is, ask whether you have been given P(Flag | Truth) or its reverse P(Truth | Flag), and reach for Bayes' theorem to convert between them. Whether you are building a spam filter, an exam-integrity detector, a disease-screening tool, or the next layer of a neural network, the questions are the same ones this chapter just answered for a ₹500 transfer between a sister and her brother.

Key Takeaways — Summary and Recap

Let us recap what we covered: the core ideas behind probability and statistics for ai, how they connect to real-world applications, and why they matter for your journey in computer science. Remember these key points as you move forward. For competitive exam preparation (CBSE, JEE, BITSAT), focus on understanding the WHY behind each concept, not just the WHAT.

← Recurrent Neural Networks and Sequence ModelsBuilding a Complete ML Project: End to End →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn