The beauty of kNN#
The question and the claim#
Nearest-neighbor methods turn a representation and a distance into a prediction. Scaling, irrelevant features, class imbalance, and the choice of k affect what nearby means. The representation must preserve distinctions relevant to the question.
What you should be able to do#
Specify the scientific target and the observations needed to address it.
Compare scaled and unscaled distances using training-side evidence. Explain how a semantically similar text can still be irrelevant to a retrieval question.
Explain the assumptions, uncertainty, and limits of your conclusion.
Worked investigation#
Tune k on training-side folds of Iris, fitting scaling within each fold, then evaluate the chosen rule on held-out flowers. The worked notebook is self-contained and uses documented teaching data. Its output is evidence about that example, not a finding about a human population.
Challenge the result#
Scaling the entire dataset before splitting leaks evaluation information. Repeatedly selecting k on the test set turns that set into validation data. Before running an analysis, predict what this failure would change. After running it, distinguish a software check from a scientific justification.
Practice and verification#
Complete the exercise, then discuss the interpretation questions. Submit a runnable notebook, your assumptions, and a short evidence-based interpretation. The shared analysis workflow defines the reporting and assessment standard.
For AI assistance, first write your own target and expected behavior. Use generated suggestions as candidates, inspect the code or claims, and retain evidence of the checks you performed. The AI analysis guide includes a saved-output activity that requires no account or paid service.
Connection across lessons#
Use classifier metrics from the preceding lessons; the next chapter formalizes the complete resampling procedure.
Earlier lecture resources#
The recordings and slides below are retained from the earlier course edition and have not been revised. Use the written chapter, revised notebook, and exercise for current definitions and procedures; earlier examples may conflict with the corrections described here.
