…
…
Choose features in a 20-question archive, predict five new questions with the nearest neighbor, try k and scaling settings, write to Elena which question stays with a person, and try the same method on a music recommendation.
The unit on learning from data is over. You learned to turn questions into numbers, find the nearest neighbor, and play with k and scaling. Elena now wants to see something concrete: "Show me a small router that works, and tell me where it is wrong."
In this task you will build your own mini model with 20 simplified questions picked from Elena's archive:
| Step | What you will do |
|---|---|
| 1–2 | Get to know the archive and decide which columns will be features |
| 3 | Find the neighbors of a new question by hand |
| 4–6 | Try k and scaling settings and read the results |
| 7–8 | Try the same method on a music app's recommendation |
| 9 | Write Elena a note on "which setting, which question stays with a person" |
Lessons used: data, features, labels (5), turning text into numbers (6), nearest neighbor (7), k and scaling (8).
You will not write code. You will read distances and votes from tables and enter the numbers, and write your decisions in your own sentences. The questions in the archive, the people, and the music table are fictional sample data; the numbers were simplified for the task.
What you'll do
Required topics
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
The second unit is over. Elena now wants to see something concrete: "Show me a small router that works, and tell me where it is wrong." You have 20 simplified questions picked from Elena's archive (fictional sample data). Each question is described with numbers: word_count is the number of words in the question, aid_k, residence_k, and enrollment_k count how many times the keywords of that unit appear in the question, channel is where the question came from, answered_by is the staff member who answered it, and unit is the unit the question went to.
| # | word_count | aid_k | residence_k | enrollment_k | channel | answered_by | unit |
|---|---|---|---|---|---|---|---|
| 1 | 5 | 1 | 0 | 0 |
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
| Aisha |
| aid |
| 2 | 9 | 2 | 0 | 0 | mobile | Aisha | aid |
| 3 | 8 | 1 | 0 | 0 | Aisha | aid |
| 4 | 7 | 2 | 0 | 0 | web | Aisha | aid |
| 5 | 4 | 1 | 0 | 0 | mobile | Aisha | aid |
| 6 | 6 | 1 | 0 | 1 | web | Aisha | aid |
| 7 | 6 | 2 | 0 | 0 | Jonas | residence |
| 8 | 4 | 0 | 2 | 0 | web | Jonas | residence |
| 9 | 10 | 0 | 1 | 0 | mobile | Jonas | residence |
| 10 | 6 | 0 | 2 | 0 | web | Jonas | residence |
| 11 | 13 | 0 | 2 | 0 | Jonas | residence |
| 12 | 5 | 0 | 1 | 0 | web | Jonas | residence |
| 13 | 9 | 1 | 1 | 0 | mobile | Jonas | residence |
| 14 | 8 | 0 | 2 | 0 | web | Jonas | residence |
| 15 | 12 | 0 | 0 | 2 | web | Diego | enrollment |
| 16 | 9 | 0 | 0 | 1 | mobile | Diego | enrollment |
| 17 | 13 | 0 | 0 | 1 | web | Diego | enrollment |
| 18 | 11 | 0 | 0 | 2 | Diego | enrollment |
| 19 | 10 | 0 | 0 | 1 | web | Diego | enrollment |
| 20 | 12 | 0 | 1 | 1 | mobile | Diego | enrollment |
This step's code cell is for members.Sign up free
Which of the seven columns will be features? Ask each column the question from lesson 5: is this value available the moment a new question reaches the desk, and does it say something about the question's unit? Which column is the label?
Look closely at the answered_by column: Aisha answered only aid questions, Jonas only residence questions, and Diego only enrollment questions. This column gives the unit away perfectly; but when a new question arrives, is it clear who will answer it? Making every column a feature was the trap in lesson 5.
This step's code cell is for members.Sign up free
Five new questions reached the desk. Their features, in the order word_count, aid_k, residence_k, enrollment_k:
| New question | word_count | aid_k | residence_k | enrollment_k |
|---|---|---|---|---|
| N1 | 6 | 2 | 0 | 0 |
| N2 | 13 | 2 | 0 | 0 |
| N3 | 5 | 0 | 2 | 0 |
| N4 | 12 | 0 | 0 | 1 |
| N5 | 7 | 0 | 0 | 0 |
The text of N5 is "What time does the cafeteria open?": none of the three keywords appears in it.
Before you leave it to the model, find the neighbors of N1 yourself. Distance is computed as in lesson 7: take the difference of the numbers in the same position, drop the minus sign, and add them all up. Enter the distances from N1 to three rows of the archive.
This step's code cell is for members.Sign up free
For each new question the model computed 20 distances and ordered the neighbors from nearest to farthest. The first three neighbors with raw numbers (no scaling):
| New question (word_count, aid_k, residence_k, enrollment_k) | 1st neighbor | 2nd neighbor | 3rd neighbor |
|---|---|---|---|
| N1 (6, 2, 0, 0) | row 7, residence, 0 | row 4, aid, 1 | row 1, aid, 2 |
| N2 (13, 2, 0, 0) | row 17, enrollment, 3 | row 2, aid, 4 | row 11, residence, 4 |
| N3 (5, 0, 2, 0) | row 8, residence, 1 | row 10, residence, 1 | row 12, residence, 1 |
| N4 (12, 0, 0, 1) | row 15, enrollment, 1 | row 17, enrollment, 1 | row 20, enrollment, 1 |
| N5 (7, 0, 0, 0) | row 3, aid, 2 | row 4, aid, 2 | row 1, aid, 3 |
With k = 1 the model reports only the unit of the 1st neighbor. With k = 3 the first three neighbors vote and the unit with the most votes wins (lesson 8). If the votes tie, the unit that comes first in the nearest-to-farthest order is chosen.
Elena told you the right units of the five questions afterward: N1 aid, N2 aid, N3 residence, N4 enrollment. N5 has no right unit: the cafeteria is not the desk's business, and a person needs to see it. For each setting, enter how many right and how many wrong predictions there are for N1–N4.
This step's code cell is for members.Sign up free
N2's problem is different: it is a 13-word question, and while the word_count column ranges from 4 to 13, the other columns range from 0 to 2. With raw distance, the column with the big numbers decides the calculation on its own (lesson 8). Now divide each column by its largest value in the archive: word_count by 13, the *_k columns by 2. The new questions are scaled with the same divisors. With scaled distance, the first three neighbors (rounded to two decimals):
| New question (word_count, aid_k, residence_k, enrollment_k) | 1st neighbor | 2nd neighbor | 3rd neighbor |
|---|---|---|---|
| N1 (6, 2, 0, 0) | row 7, residence, 0 | row 4, aid, 0.08 | row 2, aid, 0.23 |
| N2 (13, 2, 0, 0) | row 2, aid, 0.31 | row 4, aid, 0.46 | row 7, residence, 0.54 |
| N3 (5, 0, 2, 0) | row 8, residence, 0.08 | row 10, residence, 0.08 | row 14, residence, 0.23 |
| N4 (12, 0, 0, 1) | row 17, enrollment, 0.08 | row 19, enrollment, 0.15 | row 16, enrollment, 0.23 |
| N5 (7, 0, 0, 0) | row 3, aid, 0.58 | row 1, aid, 0.65 | row 16, enrollment, 0.65 |
Enter the number of right predictions for N1–N4 with scaled k = 1 and k = 3. Then think about the extreme setting: if k = 20, every question in the archive votes. How many right predictions does that setting give?
This step's code cell is for members.Sign up free
Put the results of the four experiments side by side:
| Setting | N1 | N2 | N3 | N4 | N5 | N1–N4 right |
|---|---|---|---|---|---|---|
| Raw, k = 1 | residence | enrollment | residence | enrollment | aid | 2 |
| Raw, k = 3 | aid | enrollment | residence | enrollment | aid | 3 |
| Scaled, k = 1 | residence | aid | residence | enrollment | aid | 3 |
| Scaled, k = 3 | aid | aid | residence | enrollment | aid | 4 |
| k = 20 | residence | residence | residence | residence | residence | 1 |
Now write the reason for each change in your own sentences. Look at N5 in particular: its vector is (7, 0, 0, 0), so none of the keywords you are looking for appear; its scaled nearest neighbor is 0.58 away, while for the other questions the 1st neighbor is between 0 and 0.31 away (lesson 7: the empty vector and the far neighbor).
This step's code cell is for members.Sign up free
The same method works in a music app. Here are five fictional listeners with their weekly listening hours and their ratings (0–5) for three genres:
| Listener | Weekly hours | Pop | Rap | Classical | Favorite genre |
|---|---|---|---|---|---|
| Hana | 30 | 5 | 1 | 0 | pop |
| Jonas | 8 | 1 | 5 | 0 | rap |
| Diego | 28 | 0 | 1 | 5 | classical |
| Alex | 6 | 4 | 1 | 1 | pop |
| Maya | 10 | 0 | 5 | 1 | rap |
The new listener is Kai: 29 hours a week, pop 1, rap 5, classical 0. The app will recommend a song from the genre loved by the listener nearest to Kai. First compute the raw distances, then the scaled distances. To scale, divide hours by 40 and ratings by 5. Write the scaled values to three decimals (e.g. 0.750).
This step's code cell is for members.Sign up free
The raw calculation recommends pop to Kai, and the scaled calculation recommends rap. Which recommendation is right? Decide by looking at Kai's ratings and at N2 from the help desk.
This step's code cell is for members.Sign up free
Write Elena a five-sentence note: which features you chose, which setting you recommend and how the number of right predictions changed, which questions should stay with Elena (with your criterion), what should be done about the noisy row 7, and one warning. Do not forget the warning: you chose the setting by looking at only 4 questions (lesson 8: the setting is chosen on held-out questions, and few questions say little).
This step's code cell is for members.Sign up free