KNN Classification with K values in a Loop

absherzad
absherzad New Altair Community Member
edited November 2024 in Altair RapidMiner

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

  • btibert
    btibert New Altair Community Member
    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


Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.