Question
Requirements You are to create a program in Python 3 that performs the following: 1. Loads and parses the training and testing dataset files into
Requirements
You are to create a program in Python 3 that performs the following:
1. Loads and parses the training and testing dataset files into separate NumPy ndarrays. Given what you know, the easiest way to do this is to create four separate arrays:
2D array of floats for storing training example attribute values
2D array of floats for storing testing example attribute values
1D array of strings for storing training example class labels
1D array of strings for storing testing example class labels
You can assume there are exactly 4 attribute values in the training and testing examples.
2. Classifies each testing example. You also need to output the true and predicted class label to the screen and save it into a new 1D array of strings. This is done by first computing the distance value for each pair of training and testing examples (their attribute values). Then, for each test example, find the training example with the closest distance.
You can do all that easily with NumPys vectorized functions - you shouldnt use loops for this.
3. Computes the accuracy. Go through the array of class labels for testing examples and compare the label stored in the array created in step (2). Count how many matches you get. Output the number of matches, divided by the number of testing examples as a percentage.
Additional Requirements
1. The name of your source code file should be NearestNeighbor.py. All your code should be within a single file.
2. You cannot import any package except for NumPy. Very important.
3. Your code should follow good coding practices, including good use of whitespace and use of both inline and block comments.
4. You need to use meaningful identifier names that conform to standard naming conventions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started