The 'from scratch' part is where I spent most of my time.
Start by outlining the KNN algorithm and the need for feature scaling, then describe how to implement distance calculation and majority voting from scratch. Explain how to tune k using cross-validation on the labeled data, and finally apply the tuned model to the unlabeled dataset.
Pro tip: Mention that you would standardize features before computing distances, as KNN is sensitive to scale, and discuss the trade-off between bias and variance when choosing k.
Load the labeled dataset, separate features and target, and apply feature scaling (e.g., standardization) to ensure all features contribute equally to distance calculations.
Write a function to compute Euclidean distance between a test point and all training points, then select the k nearest neighbors and assign the majority class as the prediction.
Use k-fold cross-validation on the labeled data to evaluate different values of k (e.g., 1 to 20) and select the one with the best average validation accuracy.
Train the KNN model on the full labeled dataset using the optimal k, then generate predictions for the unlabeled dataset.
If labels for the unlabeled data are available, evaluate performance; otherwise, discuss the impact of k on bias-variance and computational complexity.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.