Page 240 - AI Ver 1.0 Class 10
P. 240

Step 1     Input the unsorted data set.

               Step 2     Choose the value of K(integer)— the nearest data points.

               Step 3     For each point in the test data,
                          a.   Calculate the distance between test data and each row of training data by using Euclidean Method,
                            Manhattan Method, Minkowski Method etc.

                          b.  Sort them in ascending order with corresponding train data.
                          c.  From this sorted list, select the top ‘K’ rows.

                          d.  Find the most frequent class from these chosen ‘K’ rows. This will be your predicted class.

              Let us consider that we have a dataset containing oranges and apples in a box.
                 • First of all, we will create a plot using the oranges and apples in a box.
                 • Now whenever a new fruit is added to the box with specific features, we will choose a value of k. Let us take 3
                 as the value of k.
                 • Next, we will find the distance of the nearest 3 values and the one having the least distance will have more
                 probability to arrange the new fruit in that category.

                   Pink dot = Orange
                   Orange dot = Apple

                   X = Value to be predicted.




                                                             X
                             X                                                                 X







                    1. Nearest Neighbour              2. Nearest Neighbour              3. Nearest Neighbour
              In the 1st graph

              The value of K is 1 which means that we are taking only 1 nearest neighbour into consideration. The nearest
              value to X is a orange one hence the 1-nearest neighbour algorithm predicts that the fruit is apple.

              In the 2nd graph

              The value of K is 2. Taking 2 nearest nodes to X into consideration, we see that one is apple while the other one
              is orange. This makes it difficult for the machine to make any predictions based on the nearest neighbour and
              hence the machine is not able to give any prediction.
              In the 3rd graph

              The value of K becomes 3. Here, 3 nearest nodes to X are chosen out of which 2 are pink and 1 is orange. On the
              basis of this, the model is able to predict that the fruit is orange.

              How to choose the value of K:
                 • K is a positive integer.



                        238   Touchpad Artificial Intelligence-X
   235   236   237   238   239   240   241   242   243   244   245