Exam practice
Every question from the end of every unit, with hints and answers to open. After you check an answer, mark how you did, and come back to the ones you didn’t get.
11 questions
Unit 9 · Machine Learning
Explain, step by step, how a k-nearest-neighbor model with k = 3 decides the belt of a new district from its height and slope.
Answer
- The new district’s height and slope are measured, and scaled the same way as the examples’ (for example to 0–1 by min–max scaling).
- Its distance from every training example is worked out: the square root of (gap in height)² + (gap in slope)².
- The examples are sorted from nearest to farthest, and the 3 nearest are taken.
- Their labels vote: the belt that most of them have is the answer. (If all three differ, the nearest one’s belt is given.)
No rules are written in advance: the answer comes only from the examples.
Work out the straight-line distance between these two scaled districts, and say which is nearer to A: B or C.
A: height 0.40, slope 0.70. B: height 0.70, slope 0.30. C: height 0.10, slope 0.80.
Answer
A to B: gaps 0.30 and 0.40. √(0.30² + 0.40²) = √(0.09 + 0.16) = √0.25 = 0.5.
A to C: gaps 0.30 and 0.10. √(0.30² + 0.10²) = √(0.09 + 0.01) = √0.10 ≈ 0.32.
C is nearer to A.
A student builds a nearest-neighbor model with two features: a person’s height in centimeters (140 to 190) and their monthly pocket money in rupees (0 to 5,000). What will go wrong, and how is it fixed?
Answer
The pocket money’s numbers are much bigger: a gap of Rs 1,000 counts as much as a gap of 1,000 cm in height, which is impossible. So pocket money decides the distance almost on its own, and height hardly counts. Fix it by scaling both features to the same range before measuring, for example with min–max scaling: (value − lowest) ÷ (highest − lowest), which turns both into numbers from 0 to 1.
A model is tested on 20 districts and gets 17 right. What is its accuracy? Its test set had 12 Hill, 5 Terai and 3 Mountain districts; what accuracy would a model that always says Hill get? What does the comparison tell you?
Answer
Accuracy = 17 ÷ 20 × 100% = 85%.
Always saying Hill gets the 12 Hill districts right: 12 ÷ 20 × 100% = 60%. This is the baseline.
The model beats the baseline by 25 percentage points, so it has learned something from its features. But 85% alone would have sounded better than it is: the comparison shows how much of it is real learning.
Copy and complete this confusion table for a model tested on 30 districts, then find its accuracy and say which mistake it makes most.
| True belt | said Mountain | said Hill | said Terai |
|---|---|---|---|
| Mountain | 5 | 2 | 0 |
| Hill | 3 | 13 | 1 |
| Terai | 0 | 0 | ? |
Answer
The rows must add up to 30: 7 + 17 = 24 districts in the first two rows, so the Terai row has 6, all said Terai: ? = 6.
Right answers are on the diagonal: 5 + 13 + 6 = 24. Accuracy = 24 ÷ 30 × 100% = 80%.
Its most common mistake is calling Hill districts Mountain (3 times). It never confuses Mountain and Terai: they are far apart in height.
What is leave-one-out testing? Why is it useful for a small dataset like Nepal’s 77 districts?
Answer
Each example is tested in turn by a model trained on all the other examples. So every example is tested once, and never by a model that has it as an example. The accuracy is the number right out of all the examples.
With only 77 examples, a test set of 15 is small, and its score jumps a lot depending on which districts it happens to get (from 80% to 100% in this unit). Leave-one-out uses all 77 for testing and 76 for training each time, so the score is steadier and no data is wasted.
The model calls Bhaktapur a Terai district. Explain why, and say whether this is a fault in the program, the features, or the label.
Answer
With height and slope scaled, Bhaktapur’s nearest neighbors are Kathmandu (Hill), Dang and Chitwan (Terai), or in the widget’s training set Dang, Kailali (Terai) and Udayapur (Hill): two Terai votes to one. Bhaktapur is mostly the flat floor of the Kathmandu Valley, so its average slope (10°) is as low as that of Terai districts with some hills, and its height (1,378 m) is between.
The program is not at fault: it did exactly what nearest neighbors should. The features can’t tell a flat valley high in the hills from flat plains, at least when slope counts as much as height (with height alone, Bhaktapur is placed correctly). The label is correct: Bhaktapur is in the Hill belt.
Evaluate the districts data set under five headings: source, quality, representativeness, bias and privacy. Give one point for each.
Answer
- Source: heights from the Shuttle Radar Topography Mission (2000), rain from CHELSA’s climate model, people from the 2021 census, belts from the government’s grouping.
- Quality: the rain is a model’s estimate, weakest high in the mountains where there are few gauges; the heights had gaps in steep valleys that were filled by estimating; the census is a few years old.
- Representativeness: only 77 examples, 16 of them Mountain; whole districts only, so it can’t be used for a single village.
- Bias: each district has one label though its land spans several belts (Gorkha has Manaslu but is Hill); the model learns people’s decisions.
- Privacy: no single person is in it, only totals; the census office keeps each household’s answers secret by law.
A bank in Nepal wants to decide who gets a loan with a model trained on its last 20 years of loans. Write three questions about the data the bank should ask, and why each matters.
Answer
Any three, with reasons, such as:
- Who is in it, and who is missing? If the bank lent mostly to people in cities, or mostly to men, the model has few examples of village farmers or women, and may treat them unfairly (representativeness).
- Do the labels carry old unfairness? If the bank turned people away in the past for reasons that weren’t fair, the model learns those decisions as if they were right (bias in the labels).
- What features does it use, and could any stand in for something unfair? A home address can stand in for caste, ethnicity or wealth.
- Is the data still true? Twenty-year-old loans may say little about today’s incomes and prices (quality).
- Did customers agree, and is their data kept safe? Loan records are private, and a leak harms real people (privacy).
For each task, choose rules written by people, nearest neighbors, or a neural network, and justify your choice: (i) deciding whether a student passes from their marks, using the school’s pass mark; (ii) guessing which of three kinds of rice a grain is, from its length and width, with 300 measured grains; (iii) turning a farmer’s spoken question in Nepali into text.
Answer
- i.Rules. The rule is known and must be followed exactly (marks ≥ the pass mark), and students must be able to see why. A model could only make mistakes a rule never would.
- ii.Nearest neighbors (or a decision tree). A small table: two features, a few hundred examples. Nearest neighbors needs no rules to be known, is quick at this size, and can show which grains it compared with. A neural network would need far more data for no gain.
- iii.A neural network. Speech is a sound wave with thousands of numbers every second; nobody can write rules or choose features for it by hand. Neural networks trained on many hours of recorded Nepali speech do this, though they need large data, and must be tested on speakers from every part of Nepal.
Describe two benefits and three harms of collecting data from billions of people to train AI.
Answer
Benefits (any two): better weather and flood forecasts (GraphCast learned from decades of weather records); help for doctors finding disease in medical images; translation and voice typing in more languages; useful tools such as search and maps.
Harms (any three): people’s writing, photos and faces used without their consent (Clearview AI’s billions of face photos, fined €30.5 million in the Netherlands); surveillance, when collected data is used to follow people; leaks that expose private data; low-paid and harmful labeling work (workers in Kenya paid under $2 an hour); bias against people who are less online and so less in the data; electricity and water used by data centers.
