Derived metrics and rule-based classification: dew point, heat index and the rule ladder
Module 3 — Processing with maths and physics · Slides: slides.md · Module overview · Course page
Build the course’s first classifier without ML. Turn temperature and humidity into the derived metrics dew point and heat index, then decide a class with thresholds and a correctly ordered rule ladder.
Objectives
Section titled “Objectives”By the end of this lesson, you will:
- Explain a classifier as a box that takes numbers and returns a class, and compare hand-set rules with ML on at least two dimensions (training data, explainability, or pattern complexity).
- Call dsp.dew_point and dsp.heat_index, and explain why derived metrics help rules decide better than raw values — for example, 32°C at 40% and 80% humidity give heat index values about 12 degrees apart.
- Order a multi-step rule ladder with the more specific or severe conditions on top, and spot the dead branch in a wrongly ordered ladder.
Before you start
Section titled “Before you start”You’ve been through lessons 3.1–3.2, and understand the raw → derived → viz pattern. Keep the REPL open to try dsp.dew_point, dsp.heat_index and dsp.comfort_zone with values of your own choosing.
- Hardware: a TESAIoT Dev Kit board already flashed with BENTO’s MicroPython firmware, or the BENTO Emulator inside BENTO IDE — uses the DPS368 and SHT40 found on the TESAIoT Dev Kit (the Eva Kit doesn’t have them); the emulator simulates temperature and humidity values.
- Prior lesson: lesson 3.2 — Hands-on: four physics gauges on screen
See it work first
Section titled “See it work first”Run the ready-made rule dsp.comfort_zone(t, rh) that the firmware provides first — it answers comfortable, hot, humid, and so on, right away. Then ask “how does it know it’s hot right now?” The answer is a handful of if lines in C — not a shred of AI.
Concepts
Section titled “Concepts”A classifier is a function that takes numbers and returns one “class” label from a fixed set. The Motion model in module 1 is a classifier too, except inside it’s a neural network. Today, what’s inside is rules we set ourselves. The shape in and out is identical — what differs is how the boundary is found: hand-set rules need no training data, run immediately, and every decision can be explained — but they balloon out of control once there are many conditions, and struggle with complex patterns. ML learns a boundary from data and can capture patterns across many dimensions, but needs data, needs training, and is harder to explain “why” for. In plenty of real work, a simple threshold rule beats ML.
Raw values are sometimes hard to judge on their own — 32°C feels very different dry versus humid. A derived metric combines several raw values into a single one that’s easier to judge — in the world of ML, this is called feature engineering. dsp.dew_point(t, rh) uses the Magnus–Tetens formula to return the dew point (the closer it gets to air temperature, the more saturated the air is). dsp.heat_index(t, rh) uses the Rothfusz regression to return “how hot it feels” — for example, 32°C at 40% gives about 32°C, but at 80% gives about 44°C. Both are computed on the CM33, not the NPU. dsp.comfort_zone is a ready-made classifier that decides from the raw t and rh values with an if ladder.
The smallest unit of a rule is a single threshold, splitting the world into two classes. Where that threshold sits (such as heat index 32) is a hyperparameter — a value we choose ourselves from knowledge or a standard. Once you need several classes, you stack ifs into a rule ladder, checked top to bottom — the first one that’s true wins and returns immediately. The iron rule is: more specific or more severe conditions must sit on top. If hi >= 32 sits above hi >= 41, a value of 43 gets hot, and the danger step can never be reached — a dead branch the compiler never warns about. It has to be caught by testing.
Worked example
Section titled “Worked example”08_environment_dashboard.py is a three-card dashboard (temperature, humidity, pressure) reading the same sensors as this lesson. Run it to see the raw values first, then think about which derived metric you’d need to add to have a card say “comfortable or not.”
| File | What this file teaches |
|---|---|
| examples/08_environment_dashboard.py | Environment Dashboard: 3 cards (temperature / humidity / pressure) |
Check your understanding
Section titled “Check your understanding”The same questions are in quiz.yaml for automated checking.
-
Which of these are strengths of hand-set rules compared with ML? (select every correct answer) (multiple choice · objective 1)
- a) No training data needed, runs immediately
- b) Every decision can be explained by which condition triggered it
- c) Captures complex patterns across dozens of dimensions well
- d) Adjusts its own threshold as new data arrives
Solution
a, b — the last two are ML’s strengths, since it learns a boundary from data. Hand-set rules are lightweight, explainable, and need no training data.
-
Why does this lesson’s rule ladder decide hot and danger from heat index instead of raw temperature? (single choice · objective 2)
- a) Because heat index reads faster
- b) Because the same temperature at different humidity levels feels very different to the body, and heat index already accounts for that
- c) Because the temperature sensor isn’t accurate
- d) Because heat index is always a whole number
Solution
b — 32°C at 80% humidity feels like about 44°C. Deciding from raw temperature would miss a genuinely dangerous sweltering condition.
-
What does it mean when the dew point gets very close to air temperature? (single choice · objective 2)
- a) The air is very dry
- b) The air is close to saturated, very humid — water vapour is close to condensing into droplets
- c) The sensor is broken
- d) Temperature is dropping fast
Solution
b — as RH approaches 100%, ln(RH/100) approaches 0, making the dew point approach the real temperature. The gap t − Td is therefore a good humidity signal.
-
The ladder has
if hi >= 32: return "hot"beforeif hi >= 41: return "danger". With input hi = 43, what’s the result? (single choice · objective 3)- a) danger
- b) hot, and the danger step becomes a dead branch that can never be reached
- c) An error, because the conditions overlap
- d) comfortable
Solution
b — the ladder returns at the first true step. 43 ≥ 32, so it answers hot before ever reaching the danger step. More severe conditions must always sit on top.
- In the REPL, call
dsp.heat_index(32, 40)anddsp.heat_index(32, 80), and note the results in your learning log. - Call
dsp.comfort_zonewith three sets of values that give different classes, and write down which ladder step each set falls into. - Write a 6-step rule ladder on paper, then swap the top two steps to find an input that creates a dead branch.
Going further
Section titled “Going further”In lesson 3.4, we’ll write our own classify() in the s07_rule_classifier.py file and compare it against the firmware’s ready-made rule.
Next lesson: lesson 3.4 — Hands-on: a rule-based comfort classifier
Reflect
Section titled “Reflect”- What job can you think of where rules should be used over ML, because the decision must be explainable, or because a legal standard already sets the threshold?
- If your sensor had 50 values, where would writing a rule ladder get harder?
Review questions
Answer on your own first, then open the answer.
-
Which are strengths of hand-written rules compared with ML? (select all that apply) (Objective 1)
- ไม่ต้องมีข้อมูลฝึก รันได้ทันที
- อธิบายได้ว่าคำตัดสินมาจากเงื่อนไขใด
- จับ pattern ซับซ้อนหลายสิบมิติได้ดี
- ปรับเส้นแบ่งตามข้อมูลใหม่ได้เอง
Show answer
Answer: A. ไม่ต้องมีข้อมูลฝึก รันได้ทันที · B. อธิบายได้ว่าคำตัดสินมาจากเงื่อนไขใด
สองข้อหลังเป็นจุดแข็งของ ML ที่เรียนเส้นแบ่งจากข้อมูล ส่วนกฎมือเบา อธิบายได้ และไม่ต้องมีข้อมูลฝึก
-
Why does this lesson's ladder decide hot and danger from the heat index rather than the raw temperature? (Objective 2)
- เพราะ heat index อ่านได้เร็วกว่า
- เพราะอุณหภูมิเท่ากันแต่ความชื้นต่างกันทำให้ร่างกายรู้สึกต่างกันมาก heat index รวมผลนั้นไว้แล้ว
- เพราะเซนเซอร์อุณหภูมิไม่แม่น
- เพราะ heat index เป็นจำนวนเต็มเสมอ
Show answer
Answer: B. เพราะอุณหภูมิเท่ากันแต่ความชื้นต่างกันทำให้ร่างกายรู้สึกต่างกันมาก heat index รวมผลนั้นไว้แล้ว
32°C ที่ความชื้น 80% รู้สึกเหมือนราว 44°C ถ้าตัดสินจากอุณหภูมิดิบจะพลาดภาวะร้อนอบอ้าวที่อันตรายจริง
-
The dew point is very close to the air temperature. What does that mean? (Objective 2)
- อากาศแห้งมาก
- อากาศใกล้อิ่มตัว ชื้นมาก ไอน้ำใกล้จะกลั่นเป็นหยดน้ำ
- เซนเซอร์เสีย
- อุณหภูมิกำลังลดลงเร็ว
Show answer
Answer: B. อากาศใกล้อิ่มตัว ชื้นมาก ไอน้ำใกล้จะกลั่นเป็นหยดน้ำ
เมื่อ RH เข้าใกล้ 100% ค่า ln(RH/100) เข้าใกล้ 0 ทำให้ dew point เข้าใกล้อุณหภูมิจริง ระยะห่าง t − Td จึงเป็นสัญญาณความชื้นที่ดี
-
The ladder has if hi >= 32: return "hot" before if hi >= 41: return "danger". What does hi = 43 give? (Objective 3)
- danger
- hot และชั้น danger กลายเป็น dead branch ที่ไม่มีวันถูกเรียก
- error เพราะเงื่อนไขซ้อนกัน
- comfortable
Show answer
Answer: B. hot และชั้น danger กลายเป็น dead branch ที่ไม่มีวันถูกเรียก
บันได return ขั้นแรกที่จริง 43 ≥ 32 จึงตอบ hot ก่อนถึงชั้น danger เงื่อนไขที่รุนแรงกว่าต้องอยู่บนเสมอ
Cite this lesson
If you teach from this lesson or reuse it in slides or documents, credit it with the text below. If you changed it, add (adapted) after the title.
"Derived metrics and rule-based classification: dew point, heat index and the rule ladder" from TESA Open Knowledge by the Thai Embedded Systems Association (TESA), https://github.com/tesaiot/tesa-qualification-program, licensed under CC BY-NC 4.0
Thai attribution: "ค่าอนุพัทธ์และการจำแนกด้วยกฎ: dew point, heat index และบันไดกฎ" จาก TESA Open Knowledge โดยสมาคมสมองกลฝังตัวไทย (Thai Embedded Systems Association: TESA) https://github.com/tesaiot/tesa-qualification-program สัญญาอนุญาต CC BY-NC 4.0
Lesson link: https://tesaiot.github.io/tesa-qualification-program/en/courses/edge-ai-developer/m03-processing/l03-rules-before-ml/
TESA Open Knowledge · © 2026 สมาคมสมองกลฝังตัวไทย (TESA) · CC BY-NC 4.0
Content is licensed CC BY-NC 4.0. Reuse it non-commercially and credit the Thai Embedded Systems Association (TESA) every time. · How to cite TESA