#C14018. Iris K-Nearest Neighbors Classifier Evaluation
Iris K-Nearest Neighbors Classifier Evaluation
Iris K-Nearest Neighbors Classifier Evaluation
In this problem, you are required to implement a K-Nearest Neighbors (KNN) classifier on the famous Iris dataset. The Iris dataset contains 150 samples, each with 4 features, and the samples are labeled into 3 different classes.
Your task is to:
- Load the Iris dataset (you may use scikit-learn’s built-in data in Python or assume the data is provided in other languages).
- Split the dataset into a training set and a testing set, using a test size of 20% and a fixed random seed of 42 to guarantee reproducibility.
- Train a KNN classifier using a number of neighbors ( k ) given by the input (read from standard input).
- Evaluate the classifier on the test set and output the classification accuracy, formatted to 4 decimal places.
Note: For languages without direct support for scikit-learn, you may hardcode the expected results based on the known deterministic behavior of the dataset with the fixed split. For example, when ( k = 3 ) or ( k = 5 ), the accuracy is approximately 0.9667, and when ( k = 7 ), it is about 0.9333.
Make sure that your solution reads input from standard input (stdin) and writes output to standard output (stdout). If using libraries, ensure the output format strictly follows the specification.
inputFormat
The input consists of a single integer ( k ) (read from standard input), representing the number of neighbors to be used in the KNN classifier.
outputFormat
Output a single floating-point number on standard output, which is the accuracy of the classifier on the test dataset, formatted to 4 decimal places.## sample
3
0.9667