- 3 The Code Below Shows The K Nearest Neighbour Ann Algorithm On 3 Species Of Iris Iris Setosa Iris Virginica Iris 1 (27.14 KiB) Viewed 19 times
3) The code below shows the K-Nearest Neighbour (ANN) algorithm on 3 species of Iris (Iris setosa, Iris virginica, Iris
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
3) The code below shows the K-Nearest Neighbour (ANN) algorithm on 3 species of Iris (Iris setosa, Iris virginica, Iris
3) The code below shows the K-Nearest Neighbour (ANN) algorithm on 3 species of Iris (Iris setosa, Iris virginica, Iris versicolor). Based on the code provide, please explains algorithm procedure to obtain the best approximation of k the output of confusion matrix (5 Marks) (5 Marks) iii the best numbers of k and how we can determine the threshold values of k (maximum number of accuracy) (10 Marks) "you may run the code to answer (ii) & (iii). For (i): required modification of the code #Installing Packages install packages("e1071") install packages("caTools") install packages("class") Loading package Ibrary(1071) Ibrary(caTools) ibrary/class) Loading data data(iris) head(iris) #Splitting data into train #and test data split-sample.splitris, SplitRatio - 0.7) train de subset(iris, split "TRUE") test_cl<-subsetris, split == "FALSE") Feature Scaling train_scale-scale(train_c. 1:4) test scale-scale(test 1:4 #Fitting KNN Model to training dataset classifier knn knn(train train scale, classifier ken test test scale, cl-train_clsSpecies, cm k=1) Confusin Matrix cm-table(test_clsSpecies, classifier_kn) Model Evaluation Choosing K Calculate out of Sample error misClassError<- mean(classifier_knn t test_clsSpecies) printipastel'Accuracy, 1-misClassError) WK=2 classifier kan knntrain train scale. test test scale. dl-train c$Species, k=2) misClassError mean(classifier knn t test_clsSpecies) printipastel'Accuracy, 1-misClassError)