Implement and Tune KNN Classifier
Qube Research & TechnologiesData Scientist · Online AssessmentLast updated
This question evaluates a candidate's competency in implementing and tuning the K-nearest neighbors algorithm, covering data preprocessing, distance-based classification, model evaluation, and hyperparameter selection.
You are given two CSV files for a three-class leaf-classification task.
train.csvcontains three numeric feature columns:feature_0,feature_1, andfeature_2, plus a class label column.unlabeled.csvcontains the same three feature columns but no labels.
Complete the task in a Jupyter notebook:
- Load and inspect the labeled dataset.
- Split the labeled data into training and testing sets.
- Implement a K-nearest neighbors classifier from scratch. You may use standard data-processing libraries, but the KNN prediction logic should be your own implementation.
- Train the classifier and evaluate its accuracy on the held-out test set.
- Tune hyperparameters, especially the value of
k, and try to improve accuracy. You may use cross-validation. - Use the final model to predict labels for
unlabeled.csv. - Write the predictions to an output CSV file.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.