<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to do n-fold cross-validation in KNN in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-do-n-fold-cross-validation-in-KNN/m-p/677022#M8387</link>
    <description>&lt;P&gt;Is there any option in Proc Discrim (or another KNN procedure) that can do n-fold cross validation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just some quick background. I'm trying to use KNN to classify the fishes in the SASHelp.Fish data set. Below is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data analysis;
set sashelp.fish;
where species in ('Bream', 'Perch');
run;

data train test;
set analysis;
rand = ranuni(100);
if rand &amp;lt;= 0.8 then output train;
else output test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Above code splits the FISH data set into training and testing data set. In the training set, I want to do n-fold cross-validation to get the optimal k for KNN. See link below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://medium.com/@svanillasun/how-to-deal-with-cross-validation-based-on-knn-algorithm-compute-auc-based-on-naive-bayes-ff4b8284cff4" target="_blank"&gt;https://medium.com/@svanillasun/how-to-deal-with-cross-validation-based-on-knn-algorithm-compute-auc-based-on-naive-bayes-ff4b8284cff4&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't seem to find the Proc Discrim options that enable me to do this easily.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc discrim data = train test = test
  testout = _score1 method = npar k = 5 testlist crossvalidate crosslist;
  class species;
  var weight height;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know whether this cross-validation feature is available in Proc Discrim (or any other procedure)? If not, what's the better way to find the optimal k for KNN?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 16 Aug 2020 03:33:14 GMT</pubDate>
    <dc:creator>kisumsam</dc:creator>
    <dc:date>2020-08-16T03:33:14Z</dc:date>
    <item>
      <title>How to do n-fold cross-validation in KNN</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-do-n-fold-cross-validation-in-KNN/m-p/677022#M8387</link>
      <description>&lt;P&gt;Is there any option in Proc Discrim (or another KNN procedure) that can do n-fold cross validation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just some quick background. I'm trying to use KNN to classify the fishes in the SASHelp.Fish data set. Below is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data analysis;
set sashelp.fish;
where species in ('Bream', 'Perch');
run;

data train test;
set analysis;
rand = ranuni(100);
if rand &amp;lt;= 0.8 then output train;
else output test;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Above code splits the FISH data set into training and testing data set. In the training set, I want to do n-fold cross-validation to get the optimal k for KNN. See link below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://medium.com/@svanillasun/how-to-deal-with-cross-validation-based-on-knn-algorithm-compute-auc-based-on-naive-bayes-ff4b8284cff4" target="_blank"&gt;https://medium.com/@svanillasun/how-to-deal-with-cross-validation-based-on-knn-algorithm-compute-auc-based-on-naive-bayes-ff4b8284cff4&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't seem to find the Proc Discrim options that enable me to do this easily.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc discrim data = train test = test
  testout = _score1 method = npar k = 5 testlist crossvalidate crosslist;
  class species;
  var weight height;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know whether this cross-validation feature is available in Proc Discrim (or any other procedure)? If not, what's the better way to find the optimal k for KNN?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 03:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-do-n-fold-cross-validation-in-KNN/m-p/677022#M8387</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2020-08-16T03:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to do n-fold cross-validation in KNN</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-do-n-fold-cross-validation-in-KNN/m-p/677056#M8388</link>
      <description>&lt;P&gt;The documentation lists three different crossvalidation options.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetVersion=15.1&amp;amp;docsetTarget=statug_discrim_syntax01.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=statug&amp;amp;docsetVersion=15.1&amp;amp;docsetTarget=statug_discrim_syntax01.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 11:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-do-n-fold-cross-validation-in-KNN/m-p/677056#M8388</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-16T11:54:34Z</dc:date>
    </item>
  </channel>
</rss>

