Search the courses, subjects, tracks, games and features, or jump straight to a page.
5 cards from this section. Quick, good the night before a test.
Using the lesson's data (1 and 2 hours Fail; 3, 4 and 5 hours Pass), which three students are nearest to a student who studied 4.5 hours, and what does KNN with k = 3 predict?
Subtract each student's hours from 4.5 and ignore the sign.
Why is predicting Pass or Fail a classification task and not a regression task?
Ask whether the answer is "which group?" or "how much?".
In this example, what does the model give as its answer for a new student?
Look at the labels in the training data.
With k = 3, which students are the nearest neighbours of a student who studied 1.5 hours?
Subtract 1.5 from each student's hours and ignore the sign.
Test KNN fairly with "leave-one-out": hide one student, predict them from the other four, and repeat for every student. Compare k = 1 and k = 3. Which does better on this data, and why?
Slicing with hours[:i] + hours[i + 1:] gives the list without student i.
Borderline cases need more information. Add a second feature, the number of practice tests taken, and use the straight-line distance between two points. Seven students are recorded as (hours studied, practice tests, result): (1, 0, Fail), (2, 1, Fail), (3, 1, Fail), (2, 4, Pass), (3, 3, Pass), (4, 2, Pass) and (5, 4, Pass). Using k = 3, predict for (2.5 hours, 3 tests), (2.5 hours, 0.5 tests) and (4 hours, 1 test).
Only the distance function changes; the sorting and voting stay exactly the same.
6 more questions in this section. Enroll free to practise them all.
Enroll free