KNN Classification with K values in a Loop

absherzadabsherzad Member Posts: 1 Contributor I
edited August 2019 in Help

Greetings everyone,

Is there a way to use KNN with a loop in order to assign the index of the loop as a value for K, and then compare the results?

 

Regards,

Sherzad

Comments

  • btibertbtibert Member, University Professor Posts: 146 Guru
    Yes, please see the screenshots below.  Hope this helps.

    1)  The setup where I am setting a role , train/test split, and passing in both for access into the loop.  The output is a single row table with 1 performance metric, accuracy.  I use the append operator to put these together into 1 dataset.



    2)  Inside the loop.  I am taking the top port (training set) to fid the KNN model.  I am applying it for the given K, getting the performance stat accuracy, making that a dataset, and then setting the value of K with the advanced function using the param function.



    3)  Below is the screen where you can see I am setting the value of K.  This is what is used during each iteration of the loop.  As shown previously, we append used Performance to data to get a 1-row dataset, and then appended them all together for further analysis.

      

    4)  We can use the dataset to plot our accuracy over the K values to get a sense of what we might set using visualizations inside the results


Sign In or Register to comment.