Homework Assignment
Please complete the following tasks within one week and submit your work as a GitHub repository.
1. Extend the k-NN S3 Class (30 pts)
- Different Distances: Update your
knn_s3implementation to support adist = c("sse", "sad")argument for L1 and L2 distances. - Documentation: Add roxygen2 comments for the new argument and regenerate the help files using
devtools::document().
2. Shiny App Enhancement (30 pts)
- Dynamic Predictors: In the k-NN app, add a multi-select input that allows users to choose predictor variables at runtime.
- Download Button: Implement functionality to download the test-set predictions as a CSV file.
3. Rcpp Performance Study (30 pts)
- Benchmark Script: Create
benchmark_knn_dims.Rto compare runtimes for pure R vs Rcpp implementations across combinations of sample size \(n \in \{500, 1000, 2000\}\) and feature count \(p \in \{3, 5, 10\}\). - Summary Report: Produce a one-page PDF summarizing your benchmarks, key code changes, and performance recommendations.
Deliverables
Your GitHub repository should be organized as follows:
knn_workshop_hw/
├── R/ # R scripts and tests
├── app/ # Shiny app files
├── src/ # C++ source for Rcpp
├── benchmark_knn_dims.R
├── report.pdf # summary of benchmarks and findings
└── README.md # overview and instructions
The README must include: - Setup instructions for all components - A sample run demonstrating each part of the assignment
Good luck, and feel free to reach out with any questions!