AI · 4.2
Classification, Trees, Neighbours and Clusters
Name
Class
Date
Mark / 23
Section A
Circle the letter of the correct answer. One mark each.
- 1What is a decision boundary?1
- AThe edge between regions a classifier assigns to different classes
- BThe point where training stops improving
- CThe split between training and test data
- DThe largest value a feature is allowed to take
- 2In kNN with k = 5, a new point's nearest neighbours are 3 cats and 2 dogs. What is predicted?1
- A60% cat
- BA tie, so no prediction
- CDog
- DCat
- 3What is the risk of using k = 1 in k-nearest neighbours?1
- AFeatures no longer need to be scaled
- BEvery point is given the most common class
- COne mislabelled example creates wrong answers around it
- DThe model becomes far too slow to train
- 4What does the sigmoid function do in logistic regression?1
- ASplits the data into a training set and a test set
- BSquashes a score into a probability between 0 and 1
- CFinds the k nearest training examples to a point
- DRemoves features that the model does not need
- 5A group contains 3 apples and 1 orange. What is its Gini impurity?1
- A0.25
- B0.375
- C0.5
- D0.75
- 6How does a random forest reduce overfitting?1
- AIt grows a single tree much deeper than usual
- BIt removes every feature except the most useful one
- CMany trees trained on random samples vote, so their errors cancel
- DIt trains one tree on the test set as well
- 7A model finds 40 of the 50 real fraud cases and flags 10 genuine payments by mistake. What is its recall?1
- A20%
- B40%
- C50%
- D80%
- 8For a cancer screening test, which mistake is usually worse, and so which measure is favoured?1
- AA false negative, so recall is favoured
- BA true negative, so the F1 score is favoured
- CA true positive, so accuracy is favoured
- DA false positive, so precision is favoured
- 9In k-means, what happens in the update step?1
- AEach centroid moves to the mean of the points assigned to it
- BThe number of clusters k increases by one
- CEach point moves to the centroid it is nearest to
- DThe points with the largest distances are deleted
- 10Why is k-means usually run several times with different starting centroids?1
- AIt needs several runs before it can find any clusters
- BEach run adds one more cluster to the result
- CDifferent starts can settle on different, worse clusterings
- DRunning it again makes the clusters more equal in size
Section B
Answer in the space provided. The number of marks tells you how many separate points to make.
- 1DescribeDescribe how the k-nearest neighbours algorithm classifies a new example.4
- 2CalculateA spam filter is tested on 1,000 emails. It correctly flags 90 of the 100 spam emails and wrongly flags 30 genuine emails. Calculate its precision and recall, and explain which matters more for a spam filter.5
- 3ExplainExplain how a decision tree chooses which question to ask first.4
Mark scheme
Section A
Section B
1 Describe how the k-nearest neighbours algorithm classifies a new example. 4
One mark for each of the following, to a maximum of 4.
- Calculate the distance from the new example to every training example
- Select the k closest examples
- Count the classes of those neighbours / vote
- Predict the most common class among them
Model answer. The algorithm calculates the distance, usually the straight-line distance, from the new example to every example in the training data. It selects the k closest of these, its nearest neighbours. It then counts which class each neighbour belongs to, a vote, and predicts the class that is most common among the k neighbours.
2 A spam filter is tested on 1,000 emails. It correctly flags 90 of the 100 spam emails and wrongly flags 30 genuine emails. Calculate its precision and recall, and explain which matters more for a spam filter. 5
One mark for each of the following, to a maximum of 5.
- Recall = 90 ÷ 100 = 90%
- Precision = 90 ÷ 120
- Precision = 75%
- Precision matters more
- Because binning genuine emails is worse than letting some spam through
Model answer. Recall is TP ÷ (TP + FN) = 90 ÷ 100 = 90%. Precision is TP ÷ (TP + FP) = 90 ÷ (90 + 30) = 90 ÷ 120 = 75%. Precision matters more for a spam filter, because a genuine email sent to the spam folder may be important and never seen, whereas a spam email that gets through is only a mild annoyance. So the threshold should be raised to cut false positives.
3 Explain how a decision tree chooses which question to ask first. 4
One mark for each of the following, to a maximum of 4.
- It tries every feature and possible threshold
- It measures how pure / mixed the resulting groups are
- Using Gini impurity or entropy
- It picks the split that lowers impurity the most, weighted by group size
Model answer. The tree considers every feature and every possible threshold for it. For each candidate question it splits the training examples into two groups and measures how mixed the classes in each group are, using Gini impurity or entropy. It chooses the question that reduces the impurity the most, averaged over the two groups and weighted by their sizes, so that the groups are as pure as possible.