Classification with Ordered Thresholds

An ordered series of thresholds can classify a numeric value into nonoverlapping bands when its endpoint rules are explicit.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Start with the highest threshold
  2. Handle the valid domain first
  3. Build each band from its lower and upper bounds
  4. Test the domain and the transitions independently

Start with the highest threshold

For levels bronze below 60, silver from 60 through 79, and gold from 80 upward, checking the lower bounds in descending order ensures a score of 85 reaches gold. Overlapping tests can otherwise let an earlier silver test capture that score.

Handle the valid domain first

If scores must fall between 0 and 100 inclusive, decide what happens to a score of 105 before evaluating the band. Test 59, 60, 79, and 80 to cover the two threshold changes. Domain validation defines the inputs available to classification.[1][2]

Build each band from its lower and upper bounds

For a running score on integers from zero to one hundred, suppose scores of at least eighty earn gold and at least sixty earn silver if they do not qualify for gold. A descending sequence of lower-bound checks yields gold at eighty, silver at sixty, and bronze below sixty. Checking silver first would also accept scores of eighty and ninety. Use overlapping condition ranges to see why the test order matters when conditions share values.

Test the domain and the transitions independently

Try scores of 59, 60, 79, and 80. The pairs isolate the two boundary changes. Then test a negative score and one above one hundred if the caller may pass invalid data. Validate these before classifying, because a high invalid score could look gold otherwise.

For fractional input, decide how rounding belongs in the policy. Classifying the precise score 79.8 might differ from displaying it rounded to 80 and classifying the label. Preserve the intended raw or rounded value and document which is used. See comparison boundaries and rounding conventions.

References

  1. Python Software Foundation, Python Tutorial: Control Flow ↩
  2. Python Software Foundation, Python Language Reference: Expressions ↩