#C13443. KNN Performance Analysis on Iris Dataset
KNN Performance Analysis on Iris Dataset
KNN Performance Analysis on Iris Dataset
In this problem, you are given the well-known Iris dataset. Your task is to build a k-nearest neighbors (KNN) classifier and evaluate its performance using 5-fold cross‐validation. Specifically, for each integer k from 1 to 30, you will compute the classification accuracy. The accuracy for each k is defined as
[ Accuracy = \frac{\text{Number of Correct Predictions}}{\text{Total Number of Samples}} ]
Your goal is to determine the optimal number of neighbors, i.e. the smallest k value that gives the highest accuracy. Then, print the optimal k on the first line and the corresponding accuracy (rounded to four decimal places) on the second line.
Note: There is no input for this problem. All computations are performed on the Iris dataset embedded in the program.
inputFormat
This problem does not require any input from stdin.
outputFormat
The output should consist of exactly two lines printed to stdout:
- The first line contains the optimal number of neighbors k (an integer between 1 and 30) that yields the highest accuracy.
- The second line contains the corresponding accuracy (a float rounded to four decimal places).
13
0.9733
</p>