Chapter 70
70 / 71

Statistical Analysis

⏱️ 45 min

What you're probably confused about right now

"A high average means good performance, right?"

Not necessarily. You also need to look at dispersion and sample size.

One-line definition

Statistical analysis uses mean, median, variance, and standard deviation to describe data distribution and support decision-making.

Real-life analogy

Two classes both average 80 on a test. But one is tightly grouped, the other is all over the place. Very different conclusions.

Minimal working example

import statistics
data = [80, 90, 78, 92, 88]
print(statistics.mean(data))
print(statistics.median(data))
print(statistics.stdev(data))

Quick quiz (5 min)

  1. Calculate mean and standard deviation for two datasets.
  2. Compare which group is more stable.
  3. Write a brief conclusion.

Quiz answer guide & grading criteria

  • Answer direction: write runnable code that covers the core requirements and edge cases from the prompt.
  • Criterion 1 (Correctness): Main flow produces correct results, key branches execute.
  • Criterion 2 (Readability): Clear variable names, no excessive nesting.
  • Criterion 3 (Robustness): Basic protection against null values, type errors, or unexpected input.

Take-home task

Implement analyze_scores(scores) that returns a structured statistics result.

Acceptance criteria

You can independently:

  • Calculate core statistical metrics
  • Explain what each metric means
  • Avoid drawing conclusions from a single metric

Common errors & debugging steps (beginner edition)

  • Can't read the error: start from the last line -- find the error type (TypeError, NameError, etc.), then trace back to the line in your code.
  • Not sure about a variable's value: throw in a temporary print(var, type(var)) at key points to verify data looks right.
  • Changed code but nothing happened: make sure the file is saved, you're running the right file, and your terminal is in the correct venv.

Common misconceptions

  • Misconception: just look at the mean and you're good.
  • Reality: combine variance/standard deviation with sample size.