Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Machine Learning Notes
Topic #318

Random Variables

A random variable is a variable whose value is the numeric outcome of a random process. It's the formal bridge between "something uncertain happens" and "here's a number I can compute with."

Discrete vs Continuous

Discrete Random VariableContinuous Random Variable
Possible valuesCountable (finite or countably infinite list)Any value in a range (uncountably many)
ExampleNumber of defective items in a batch of 10Time until a server responds to a request
Described byProbability Mass Function (PMF): \(P(X=x)\)Probability Density Function (PDF): \(f(x)\)
ML exampleA predicted class label (0 or 1)A predicted house price

Notation

\[ X = \text{the random variable (e.g. "number of heads in 3 coin flips")} \] \[ P(X = 2) = \text{the probability that } X \text{ takes the specific value } 2 \]

Numerical Example

Let \(X\) = number of heads in 2 fair coin flips. Possible outcomes: HH, HT, TH, TT (each with probability 0.25).

# X can be 0, 1, or 2
# P(X=0) = P(TT) = 0.25
# P(X=1) = P(HT) + P(TH) = 0.5
# P(X=2) = P(HH) = 0.25

import numpy as np
outcomes = ["HH", "HT", "TH", "TT"]
X = [outcome.count("H") for outcome in outcomes]
print(X)   # [2, 1, 1, 0]

Why This Matters for ML

  • A classifier's predicted label is modeled as a random variable — that's what makes predict_proba() meaningful in the first place
  • Every feature in your dataset can be thought of as a sample drawn from some underlying random variable — this framing underlies statistical assumptions many models make

Common Mistakes

  • Treating a continuous variable's PDF value \(f(x)\) as a probability directly — for continuous variables, only the area under the curve over a range gives a probability; \(f(x)\) at a single point is a density, not a probability.

Interview Relevance

Q: "Is a predicted class label from a classifier discrete or continuous?" Discrete — it takes one of a finite, countable set of values (the class labels); the model's underlying probability output, however, is continuous (any value in [0,1]).

Practice Question

Is "number of customer support tickets filed in a day" a discrete or continuous random variable? What about "time between two consecutive tickets"?

Related ML Notes

Want to go beyond the notes?

Join CodingNow's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →