Week 2 — Some Math

IAT 461 / 882 · Data Science for Human-Centered Systems · Summer 2026 . Alireza Karduni

Probability

What is probability?

  • A formal way to reason about how likely something is to happen
  • Built on counting outcomes

Setting up: an experiment

  • An experiment is any procedure with a set of possible outcomes
  • Example: roll two dice — one red, one blue
  • Each face shows a number from 1 to 6

The sample space

All 36 possible outcomes of rolling two dice:

Each cell = one outcome (red die, blue die) · 36 outcomes total

An event: sum equals 7

An event is any subset of the sample space we care about.

An event: sum equals 7

An event is any subset of the sample space we care about.

Highlighted outcomes all have red + blue = 7 6 out of 36

Probability of an event

\[P(E) = \frac{\text{outcomes in } E}{\text{total outcomes}} = \frac{6}{36} = \frac{1}{6}\]

  • Each outcome is equally likely: \(p = \tfrac{1}{36}\)
  • \(P(E)\) is the sum of probabilities of outcomes in \(E\)
  • Probabilities always sum to 1 across the full sample space

So what is the probability of getting a dice total of 7 OR 11?

So what is the probability of getting a dice total of 7 OR 11?

So what is the probability of getting a dice total of 7 OR 11?

At least one dice is even?

at leat one is Even OR is a 7 or 11?

at leat one is Even AND is a 7 or 11?

At least one dice is even OR is a 7 or 11?

conditional probability

Meet the department

Games No Games Total
Coding 18 12 30
No Coding 22 18 40
Total 40 30 70

Who likes games?

Games No Games Total
Coding 18 12 30
No Coding 22 18 40
Total 40 30 70

\(P(\text{Games}) = \frac{40}{70} \approx 0.57\)

Who likes coding?

Games No Games Total
Coding 18 12 30
No Coding 22 18 40
Total 40 30 70

\(P(\text{Coding}) = \frac{30}{70} \approx 0.43\)

Who likes both?

Games No Games Total
Coding 18 12 30
No Coding 22 18 40
Total 40 30 70

\(P(\text{Games} \cap \text{Coding}) = \frac{18}{70} \approx 0.26\)

Conditional probability

We know a student likes coding.

Does that tell us anything about whether they like games?

Limit your view

Games No Games Total
Coding 18 12 30
No Coding 22 18 40
Total 40 30 70

We only care about the 30 coders.

A smaller world

Among the 30 coders:

Games No Games Total
Coding 18 12 30

The denominator is no longer 70.
It is 30.

P(Games | Coding)

  • Among the 30 coders, 18 also like games.

  • \[P(\text{Games} \mid \text{Coding}) = \frac{18}{30} = 0.60\]

  • Compare to: \[P(\text{Games}) = \frac{40}{70} \approx 0.57\]

  • Knowing someone codes makes them more likely to also game.

The general formula

\[P(A \mid B) = \frac{P(A \cap B)}{P(B)}\]

  • \(P(A \cap B)\) — both happen — \(\frac{18}{70}\)
  • \(P(B)\) — B alone — \(\frac{30}{70}\)
  • The 70s cancel: \(\frac{18/70}{30/70} = \frac{18}{30} = 0.60\)

Does it work the other way?

  • Among the 40 gamers, 18 also like coding.

  • \[P(\text{Coding} \mid \text{Games}) = \frac{18}{40} = 0.45\]

  • Compare to \(P(\text{Coding}) = \frac{30}{70} \approx 0.43\)

  • \(P(\text{Games} \mid \text{Coding}) = 0.60\) vs \(P(\text{Coding} \mid \text{Games}) = 0.45\)

Bayes’ Theorem

Alex

Alex spends hours analyzing what makes games work, talks about mechanics and level design, knows what Unity and Unreal are, and has strong opinions about why certain games succeed or fail.

Is Alex more likely to be a game developer or a content creator?

What’s your guess?

Take a moment.

Most people guess game developer.

Let’s check.

How many of each are there?

  • About 10 million game developers worldwide
  • About 200 million content creators worldwide
  • Ratio: roughly 1 to 20

Start with what we know

210 people total.

10 game developers (left column)

200 content creators

This is our population.

Step 1: The hypothesis

Our hypothesis H:

  • Alex is a game developer.

  • The prior — how likely is H before we look at the description?

  • \[P(H) = \frac{10}{210} \approx 0.048\]

  • Less than 5%.

Step 2: The evidence

The description of Alex is our evidence E.

“…analyzes games, talks about mechanics, knows Unity and Unreal…”

Now we ask two questions:

  1. If Alex is a dev, how likely is this description?
  2. If Alex is not a dev, how likely is this description?

P(E | H) — evidence given the hypothesis is true

  • Among the 10 game developers, how many fit Alex’s description?

  • \[P(E \mid H) = 0.40\]

  • 4 out of 10 developers talk about mechanics, know Unity, etc. The description fits developers pretty well.

P(E | ¬H) — evidence given the hypothesis is false

  • Among the 200 content creators, how many fit the description?

  • \[P(E \mid \neg H) = 0.10\]

  • 20 out of 200 content creators also talk about game design, know engines, etc.

  • Lower rate — but there are so many more of them.

Both together

Everyone who fits the description:

  • 4 game developers
  • 20 content creators

24 total match the evidence.

P(H | E) — the answer

Of the 24 who fit the description, how many are actually developers?

  • \[P(H \mid E) = \frac{4}{4 + 20} = \frac{4}{24} \approx 0.17\]

  • Only 17% chance Alex is a developer.

  • Despite the description fitting developers 4x better, the base rate dominates.

Updating beliefs

  • We started believing there’s a 5% chance Alex is a dev
  • The description fits developers better — 4x more likely
  • But after seeing the evidence, we update to 17%
  • Our belief went up — but not as much as intuition suggests
  • The base rate anchors the answer

The formula

\[P(H \mid E) = \frac{P(E \mid H) \cdot P(H)}{P(E)}\]

  • \(P(H) = \frac{10}{210}\) — the prior
  • \(P(E \mid H) = 0.40\) — the likelihood
  • \(P(E) = \frac{24}{210}\) — the evidence
  • \(P(H \mid E) = \frac{4}{24} \approx 0.17\) — the posterior

The prior

\[P(H \mid E) = \frac{P(E \mid H) \cdot \boxed{P(H)}}{P(E)}\]

\(P(H) = \frac{10}{210} \approx 0.048\)

How likely is Alex a dev before we see any evidence?

Less than 5%.

The likelihood

\[P(H \mid E) = \frac{\boxed{P(E \mid H)} \cdot P(H)}{P(E)}\]

\(P(E \mid H) = 0.40\)

If Alex is a dev, how likely is this description?

4 out of 10 devs fit.

The evidence given ¬H

\(P(E \mid \neg H) = 0.10\)

If Alex is not a dev, how likely is this description?

20 out of 200 creators fit.

Lower rate — but so many more of them.

The total evidence

\[P(H \mid E) = \frac{P(E \mid H) \cdot P(H)}{\boxed{P(E)}}\]

\[P(E) = P(E|H) \cdot P(H) + P(E|\neg H) \cdot P(\neg H)\]

\[= 0.40 \times \frac{10}{210} + 0.10 \times \frac{200}{210}\]

\[= \frac{4 + 20}{210} = \frac{24}{210}\]

The posterior

\[\boxed{P(H \mid E)} = \frac{P(E \mid H) \cdot P(H)}{P(E)}\]

\[= \frac{0.40 \times \frac{10}{210}}{\frac{24}{210}} = \frac{4}{24} \approx 0.17\]

Only 17% chance Alex is a dev.

Despite fitting 4x better, the base rate wins.

Probability Distributions

From outcomes to distributions

We’ve been counting individual outcomes.

But often we care about a summary value — like the sum of two dice.

How often does each sum appear?

Every possible sum

Sum = 2 → only 1 way

\(P(\text{sum} = 2) = \frac{1}{36}\)

Sum = 3

Sum = 3 → 2 ways

\(P(\text{sum} = 3) = \frac{2}{36}\)

Sum = 7

Sum = 7 → 6 ways

\(P(\text{sum} = 7) = \frac{6}{36} = \frac{1}{6}\)

The most common sum.

Sum = 12

Sum = 12 → only 1 way

\(P(\text{sum} = 12) = \frac{1}{36}\)

Just as rare as sum = 2.

Count them all

Sum 2 3 4 5 6 7 8 9 10 11 12
Ways 1 2 3 4 5 6 5 4 3 2 1

What if we plot this?

The probability mass function (PMF)

Each bar = probability of exactly that sum · All bars add to 1

How to read a PMF

  • Used for discrete variables — values you can list and count
  • The x-axis shows each possible value
  • The y-axis shows the probability of exactly that value
  • The tallest bar is the most likely outcome
  • All bars sum to 1

Cumulative distribution (CDF) — discrete

Each point = probability that the sum is at most x · Always goes up · Ends at 1

How to read a CDF

  • The y-axis is \(P(X \leq x)\) — “at most this value”
  • The curve always increases
  • It ends at 1 — all outcomes are at most the maximum
  • Steeper sections = more probability mass there
  • Flat sections = no probability mass there

PMF vs CDF — same information

PMF\(P(X = x)\)

CDF\(P(X \leq x)\)

You can always convert: \(P(X = k) = C(k) - C(k-1)\)

What about continuous variables?

Dice sums are discrete — you can list every possible value.

But many real-world measurements are continuous:

  • Height — 162.3 cm, 175.8 cm, 168.1 cm…
  • Weight, temperature, reaction time
  • There are infinitely many possible values

We can’t assign probability to each exact value.

Example: heights of students

Imagine measuring the height of every student in the university.

Instead of asking “what’s the probability of being exactly 170.000 cm?”

We ask: “what’s the probability of being between 168 cm and 172 cm?”

From histogram to PDF

A histogram groups measurements into bins and counts them.

. . .

Normalize so the total area = 1, and it becomes a probability density function (PDF).

. . .

The y-axis is density, not probability.

The probability density function (PDF)

The shaded area = P(168 cm ≤ height ≤ 172 cm) · Total area under the curve = 1

PMF vs PDF — key difference

PMF (discrete) PDF (continuous)
Y-axis Probability Density
Read directly? Yes — bar height = P(X = x) No — must compute area
Probability of exact value Can be > 0 Always 0
How to get probability Read the bar Compute the area under the curve
Sums/integrates to 1 1

CDF for continuous variables

Smooth S-curve · Steepest near the mean (170 cm) · P(height ≤ 170) = 0.5

The normal (Gaussian) distribution

±1σ68% · ±2σ95% · ±3σ99.7%

How to read the bell curve

  • Centered at the mean \(\mu\)
  • Width controlled by standard deviation \(\sigma\)
  • Small \(\sigma\) → tall and narrow → values cluster tightly
  • Large \(\sigma\) → short and wide → values spread out
  • Most data falls within 2 standard deviations of the mean

Example: heights

\(\mu = 170\) cm, \(\sigma = 7\) cm

  • 68% of students are between 163 cm and 177 cm
  • 95% are between 156 cm and 184 cm
  • 99.7% are between 149 cm and 191 cm
  • Someone 2 meters tall? That’s more than 4σ away — very rare

Why this matters

  • Many natural measurements are approximately normal
  • When you report \(\mu \pm \sigma\), you’re describing this shape
  • If your data isn’t bell-shaped, the mean can mislead
  • Always plot your distribution before summarizing it

Descriptive Statistics

Summarizing data

We often have too much data to look at individually.

We need numbers that summarize a data set.

Two questions:

  • What’s the center?
  • How spread out is it?

Example: daily screen time

Imagine we surveyed 30 students about their daily screen time (hours):

Notice the long tail on the right — a few heavy users.

The mean

\[\mu = \frac{1}{n}\sum_{i=1}^n x_i\]

Sum all values, divide by count.

. . .

\(\mu = \frac{156.3}{30} = 5.2\) hours

. . .

But does 5.2 hours feel like the typical student?

The median

The middle value when data is sorted.

. . .

Median = 4.75 hours

. . .

Half the students are above, half below.

. . .

The mean (5.2) is pulled right by heavy users.

The median is more robust.

What outliers do

Drag the slider to change the heaviest user’s screen time.

. . .

The mean chases the outlier.

The median barely moves.

. . .

For skewed data, the median is usually the better summary.

Box plot

A box plot shows five numbers at once:

  • Whiskers — range excluding outliers

  • Box — middle 50% of data (Q1 to Q3)

  • Line — the median

  • Dots — outliers beyond 1.5 × IQR

  • The IQR (interquartile range) = Q3 - Q1

  • This is a robust measure of spread — outliers don’t affect it.

The mode

The most frequent value.

In our data, 4.5 hours appears twice — technically the mode.

But with continuous data, the mode is rarely useful.

The peak of the histogram is more meaningful than any single repeated value.

Which centrality measure to use?

Measure Best for Sensitive to outliers?
Mean Symmetric data, no outliers Yes
Median Skewed data, outliers present No
Mode Categorical data No

When in doubt, report both mean and median — the gap between them tells you about skewness.

Variability: standard deviation

\[\sigma = \sqrt{\frac{\sum(x_i - \bar{x})^2}{n-1}}\]

  • How far, on average, are values from the mean?

  • For our data: \(\sigma \approx 2.6\) hours

  • The shaded region shows \(\mu \pm 1\sigma\)

Why n - 1?

  • Dividing by \(n\) gives the population standard deviation
  • Dividing by \(n - 1\) gives the sample standard deviation
  • A sample of 1 tells you nothing about spread
  • With \(n - 1\), one observation gives \(\sigma = 0/0\) — undefined, as it should be
  • For large \(n\), the difference doesn’t matter

Low variance vs high variance

\(\mu = 5\), \(\sigma = 0.8\)

Everyone is similar.

\(\mu = 5\), \(\sigma = 3.0\)

Huge variation.

Same mean — completely different distributions. Always report \(\mu \pm \sigma\).

Chebyshev’s inequality

Regardless of the distribution shape:

Within Guaranteed fraction
\(\pm 1\sigma\) 0% (no guarantee)
\(\pm 2\sigma\) at least 75%
\(\pm 3\sigma\) at least 89%

For a normal distribution, the bounds are much tighter: 68%, 95%, 99.7%.

This is why \(\mu \pm \sigma\) is such a powerful summary.

Take-home lesson

  • Center: mean (symmetric data) or median (skewed data)
  • Spread: standard deviation \(\sigma\)
  • Always report both: \(\mu \pm \sigma\)
  • Always plot your data — numbers alone can hide the shape
  • Beware of outliers — they distort the mean and inflate \(\sigma\)

Correlation

What is correlation?

We say two variables are correlated when knowing one tells you something about the other.

More screen time → more apps installed?

More screen time → lower GPA?

The strength and direction of this relationship is what we want to measure.

Strong positive correlation

Screen time vs apps installed.

  • As one goes up, so does the other
  • Points cluster around a rising line
  • This is a positive correlation
  • \(r \approx +0.85\)

Strong negative correlation

Screen time vs GPA.

  • As one goes up, the other goes down
  • Points cluster around a falling line
  • This is a negative correlation
  • \(r \approx -0.80\)
  • Negative correlations are just as useful for prediction

No correlation

Screen time vs height.

  • No pattern — points are scattered randomly
  • The line is nearly flat
  • Knowing one tells you nothing about the other
  • \(r \approx 0\)

The correlation coefficient

\[r = \frac{\sum(X_i - \bar{X})(Y_i - \bar{Y})}{\sqrt{\sum(X_i-\bar{X})^2}\sqrt{\sum(Y_i-\bar{Y})^2}}\]

How much does it explain? r²

\(r^2\) = fraction of variance in \(Y\) explained by \(X\).

  • \(r = 0.8\)\(r^2 = 0.64\) → explains 64%
  • \(r = 0.5\)\(r^2 = 0.25\) → explains only 25%
  • \(r = 0.1\)\(r^2 = 0.01\) → explains 1%
  • Weak correlations have very little predictive power
  • \(r\) drops fast — don’t be fooled by moderate values

Correlation ≠ Causation

Ice cream sales and drowning deaths are strongly correlated.

  • \(r \approx 0.99\)

  • Does ice cream cause drowning?

  • No — summer causes both.

  • Heat → more swimming → more drownings.

  • Heat → more ice cream sales.

The hidden cause is called a confound.

Confounds

A confound is a hidden variable that causes both observed variables.

  • Police presence ↑ → crime rate ↑ — police don’t cause crime, high-crime areas get more police
  • Medicine intake ↑ → illness ↑ — medicine doesn’t cause illness, sick people take medicine
  • Establishing causation requires a controlled experiment

Pearson vs Spearman

\(y = x^3\) is perfectly monotonic — as x goes up, y always goes up.

  • Pearson measures linear fit — misses the curve, gives low \(r\)
  • Spearman measures monotonic fit — detects the relationship, gives \(\rho \approx 1\)
  • Spearman is also more robust to outliers
  • Use Pearson for linear relationships, Spearman when the relationship may be non-linear

Logarithms

What is a logarithm?

\[y = \log_b x \iff b^y = x\]

In plain English: how many times do I multiply \(b\) to get \(x\)?

\[\log_2 8 = 3 \quad \text{because} \quad 2^3 = 8\] \[\log_{10} 1000 = 3 \quad \text{because} \quad 10^3 = 1000\]

  • Exponentials grow very fast
  • Logarithms grow very slowly
  • They are inverses of each other

Three roles in data science

  • ① Multiplying probabilities — convert products to sums for numerical stability
  • ② Handling ratios — make increases and decreases symmetric
  • ③ Normalizing skewed data — stretch the left, compress the right

Role 1: Multiplying probabilities

Imagine a spam filter checking 10 words in an email.

Each word has a small probability of appearing in spam:

\[P(\text{spam}) \propto 0.8 \times 0.3 \times 0.9 \times 0.1 \times \cdots\]

With 100 words: \(0.5^{100} \approx 0.0000000000000000000000000000008\)

Floating point underflow — the computer rounds this to zero.

The log trick

\[\log(p_1 \times p_2 \times \cdots \times p_n) = \log p_1 + \log p_2 + \cdots + \log p_n\]

Instead of multiplying tiny numbers, sum their logarithms.

Note: log probabilities are always negative since \(\log(p) < 0\) for \(0 < p < 1\)

Role 2: Ratios are asymmetric

If something doubles: ratio = \(2/1 = 2.0\)\(+100\%\)

If something halves: ratio = \(1/2 = 0.5\)\(-50\%\)

A doubling and a halving should cancel out — but the average of 2.0 and 0.5 is 1.25, not 1.

Raw ratios are asymmetric — there’s more room above 1 than below.

Before: plotting raw ratios

The red line = ratio of 1 (no change).

  • Points above the line: improvements — lots of space
  • Points below the line: decreases — cramped between 0 and 1
  • Hard to compare magnitudes above and below
  • A ratio of 8 looks dramatic; a ratio of 0.1 looks small but is equally extreme

After: plotting log ratios

Same data — logged.

  • \(\log(2) = 0.69\) → doubling
  • \(\log(0.5) = -0.69\) → halving
  • Symmetric around zero
  • Equal space above and below the line
  • A doubling and a halving now look equally extreme

Role 3: Skewed distributions

Our screen time data — skewed right.

  • A few heavy users pull the tail out
  • Mean is misleading
  • Hard to model with standard tools
  • Many real-world distributions look like this: income, city sizes, website traffic

After log transform

Same data after \(\log\) transform.

  • Distribution is much more symmetric
  • Long right tail is compressed
  • Easier to model and analyze
  • Mean is now more meaningful
  • This is called a log-normal distribution

Log scales on axes

Linear scale — exponential growth looks like a hockey stick

Log scale — exponential growth becomes a straight line

When to use a log scale

  • Data spans multiple orders of magnitude (0.001 to 1,000,000)
  • You expect exponential growth — population, viral spread, compound interest
  • Comparing percentage changes rather than absolute changes
  • Plotting ratios or probabilities

A straight line on a log scale means constant percentage growth — a very common and important pattern in data.

Take-home

  • \(\log\) converts multiplication to addition — numerical stability
  • \(\log\) makes ratios symmetric — equal treatment of increases and decreases
  • \(\log\) normalizes skewed distributions — pulls in long tails
  • \(\log\) axes reveal exponential patterns as straight lines
  • When in doubt with right-skewed data — try taking the log