Question: Python 2.7 Coding for nearest neighbor, only import allowed is NumPy (no csv, math, panda, etc.) CSV data hyperlink, same as image: https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data The learning
Python 2.7 Coding for nearest neighbor, only import allowed is NumPy (no csv, math, panda, etc.)
CSV data hyperlink, same as image: https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
The learning will be done by remembering training examples stored in a comma-separated file. The training examples include different measurements which collectively are called features or attributes and a class label for different instances
. These are:
1. sepal length in cm
2. sepal width in cm
3. petal length in cm
4. petal width in cm
5. class: Iris Setosa, Iris Versicolour, Iris Virginica
To see how well the program learned, you will then load a file containing testing examples, which will include the same type of information, but for different nstances. For each test instance, you will apply the Nearest Neighbor algorithm to classify the instance. This algorithm works by choosing a class label of the closest training example, where closest means shortest distance. The distance is computed using the following formula:
????????(??, ??) = (sq root of)?(?????? ? ??????) 2 +(?????? ? ??????) 2 + (?????? ? ??????) 2 + (?????? ? ??????) 2
After you finish classifying each testing instance, you will then need to compare it to the true label that is specified for each example and compute the accuracy.
Accuracy is measured as the number of correctly classified instances divided by the number of total testing instances.
Requirements
Create a program in Python 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 iterating over the array of testing examples and computing the index of the closest training example. Then copying over the class label of the found training example into the new 1D array containing the predicted labels for the corresponding index.
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. All your code should be within a single file.
2. You cannot import any package except for NumPy!!!!
3. The output of your program should match the sample program output in image.




Sample Program Output 78-511, [semester] [year NAME: [put your name here] PROGRAMMING ASSIGNMENT 3 True, Predicted 1 Iris-setosa Iris-setosa 2 Iris-setosa Iris-setosa 3 Iris-setosa Iris-setosa 4 Iris-setosa Iris-setosa 5 Iris-setosa Iris-setosa 6 Iris-setosa Iris-setosa 7 Iris-setosa Iris-setosa 8 Iris-setosa Iris-setosa 9 Iris-setosa Iris-setosa 1 Iris-setosa Iris-setosa 11 Iris-setosa Iris-setosa 12 Iris-setosa Iris-setosa 13 Iris-setosa Iris-setosa 14 Iris-setosa Iris-setosa 15 Iris-setosa Iris-setosa 16 Iris-setosa Iris-setosa 17 Iris-setosa Iris-setosa 18 Iris-setosa Iris-setosa 19 Iris-setosa Iris-setosa 2 Iris-setosa Iris-setosa 21 Iris-setosa Iris-setosa 22 Iris-setosa Iris-setosa 23 Iris-setosa Iris-setosa 24 Iris-setosa Iris-setosa 25 Iris-setosa Iris-setosa 26 Iris-versicolor Iris-versicolor 27 Iris-versicolor Iris-versicolor 28 Iris-versicolor Iris-versicolor 29 Iris-versicolor Iris-versicolor 38 Iris-versicolor Iris-versicolor 31 Iris-versicolor Iris-versicolor 32 Iris-versicolor Iris-versicolor 33 Iris-versicolor Iris-versicolor 34 Iris-versicolor Iris-versicolor 35 Iris-versicolor Iris-versicolor 36 Iris-versicolor Iris-versicolor 37 Iris-versicolor Iris-versicolor 38 Iris-versicolor Iris-versicolor 39 Iris-versicolor Iris-versicolor 48 Iris-versicolor Iris-versicolor 41 Iris-versicolor Iris-versicolor 42 Iris-versicolor Iris-versicolor 43 Iris-versicolor Iris-versicolor 4 Iris-versicolor Iris-versicolor 45 Iris-versicolor Iris-versicolor 46 Iris-versicolor Iris-virginica 47 Iris-versicolor Iris-versicolor 48 Iris-versicolor Iris-virginica 49 Iris-versicolor Iris-versicolor Sample Program Output 78-511, [semester] [year NAME: [put your name here] PROGRAMMING ASSIGNMENT 3 True, Predicted 1 Iris-setosa Iris-setosa 2 Iris-setosa Iris-setosa 3 Iris-setosa Iris-setosa 4 Iris-setosa Iris-setosa 5 Iris-setosa Iris-setosa 6 Iris-setosa Iris-setosa 7 Iris-setosa Iris-setosa 8 Iris-setosa Iris-setosa 9 Iris-setosa Iris-setosa 1 Iris-setosa Iris-setosa 11 Iris-setosa Iris-setosa 12 Iris-setosa Iris-setosa 13 Iris-setosa Iris-setosa 14 Iris-setosa Iris-setosa 15 Iris-setosa Iris-setosa 16 Iris-setosa Iris-setosa 17 Iris-setosa Iris-setosa 18 Iris-setosa Iris-setosa 19 Iris-setosa Iris-setosa 2 Iris-setosa Iris-setosa 21 Iris-setosa Iris-setosa 22 Iris-setosa Iris-setosa 23 Iris-setosa Iris-setosa 24 Iris-setosa Iris-setosa 25 Iris-setosa Iris-setosa 26 Iris-versicolor Iris-versicolor 27 Iris-versicolor Iris-versicolor 28 Iris-versicolor Iris-versicolor 29 Iris-versicolor Iris-versicolor 38 Iris-versicolor Iris-versicolor 31 Iris-versicolor Iris-versicolor 32 Iris-versicolor Iris-versicolor 33 Iris-versicolor Iris-versicolor 34 Iris-versicolor Iris-versicolor 35 Iris-versicolor Iris-versicolor 36 Iris-versicolor Iris-versicolor 37 Iris-versicolor Iris-versicolor 38 Iris-versicolor Iris-versicolor 39 Iris-versicolor Iris-versicolor 48 Iris-versicolor Iris-versicolor 41 Iris-versicolor Iris-versicolor 42 Iris-versicolor Iris-versicolor 43 Iris-versicolor Iris-versicolor 4 Iris-versicolor Iris-versicolor 45 Iris-versicolor Iris-versicolor 46 Iris-versicolor Iris-virginica 47 Iris-versicolor Iris-versicolor 48 Iris-versicolor Iris-virginica 49 Iris-versicolor Iris-versicolor
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
