InnoWorks Press · Data Analytics practicals
In this chapter
  1. Try the investigation
  2. Two estimands
  3. Three evidence moves
  4. What the figure asks
  5. Code and captured output
Data Analytics / Chapter 01

The first ledger

Four rooms, one ledger, two answers. Change the occupied seat-hours and watch the question alter the answer—even when each room’s hot fraction stays fixed.

Synthetic teaching data. The 20% inspection line in the chapter is an illustrative policy choice. These records do not diagnose a ventilation fault.

Try the investigation

For each room, the hot fraction stays fixed. Edit only its occupied seat-hours. Tick a room off to change the observed population.

IncludeRoomHot fractionSeat-hours

Write down what each answer represents. Which one answers “What fraction of recorded occupied student-seat-hours were hot?”

Three evidence moves

  1. Define: identify the population, unit, time window, outcome and decision before calculating.
  2. Challenge: remove room D. Explain why the estimated seat-hour rate changes.
  3. Transfer: write an analysis contract for a clinic queue, bus route or farm sensor. Name an absent event that could alter the denominator.

What the figure asks

Bars show synthetic hot fractions of 20, 40, 60 and 80 percent in rooms A to D. A line at 60 percent marks the direct student-seat-hour rate.

Why does the seat-hour answer differ from the mean of four room rates? The plotted line is an observed ratio in this invented dataset, not a probability of a faulty system.

The reproducible notebook

Inspect the work.

Read the programs, run them in your own environment, and compare the results. The captured output records the chapter’s checked practical run; changing an input may change its answer.

Python investigation.py
"""Chapter 2: synthetic classroom estimands; run with Python 3."""
import csv
from pathlib import Path

DATA = Path(__file__).with_name("classrooms.csv")


def read_rooms(path=DATA):
    with path.open(newline="", encoding="utf-8") as handle:
        rows = list(csv.DictReader(handle))
    assert rows and len({row["room"] for row in rows}) == len(rows)
    for row in rows:
        for key in ("hot_intervals", "intervals", "hot_seat_hours", "seat_hours"):
            row[key] = int(row[key])
        assert 0 <= row["hot_intervals"] <= row["intervals"]
        assert 0 <= row["hot_seat_hours"] <= row["seat_hours"]
    return rows


def describe(rows):
    room_mean = sum(row["hot_intervals"] / row["intervals"] for row in rows) / len(rows)
    seat_rate = sum(row["hot_seat_hours"] for row in rows) / sum(row["seat_hours"] for row in rows)
    return room_mean, seat_rate


def main():
    rows = read_rooms()
    room_mean, seat_rate = describe(rows)
    print(f"Room mean: {room_mean:.1%}")
    print(f"Student-seat-hour rate: {seat_rate:.1%}")
    without_d = [row for row in rows if row["room"] != "D"]
    mean_without_d, seat_without_d = describe(without_d)
    print(f"Without D — room mean: {mean_without_d:.1%}; seat-hour rate: {seat_without_d:.1%}")
    doubled_a = [dict(row) for row in without_d]
    doubled_a[0]["hot_seat_hours"] *= 2
    doubled_a[0]["seat_hours"] *= 2
    print(f"Without D, A doubled — seat-hour rate: {describe(doubled_a)[1]:.1%}")
    assert (room_mean, seat_rate) == (0.5, 0.6)
    assert abs(seat_without_d - 280 / 600) < 1e-12
    assert abs(describe(doubled_a)[1] - 300 / 700) < 1e-12


if __name__ == "__main__":
    main()
Output Checked chapter run
Room mean: 50.0%
Student-seat-hour rate: 60.0%
Without D — room mean: 40.0%; seat-hour rate: 46.7%
Without D, A doubled — seat-hour rate: 42.9%