我资讯分类与K值n a Loop

absherzadabsherzad MemberPosts:1Contributor I
edited August 2019 inHelp

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 ProfessorPosts:146Guru
    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


    lionelderkrikor sgenzer Tghadially
Sign InorRegisterto comment.