Re: Why does `kNearestNeighbours` return more neighbours than `m_kNN` specified?

Eibe Frank <[email protected]> Wed, 14 Feb 2024 20:58:01 +0000
Newsgroups gmane.comp.ai.weka
Message-ID <SY8P282MB43865E5A0236DDFE77601FA4D74E2@SY8P282MB4386.AUSP282.PROD.OUTLOOK.COM>
IBk does not break ties. If the k-th instance has distance d, and there are further instances with distance d, they will be included in the set of nearest neighbours.

Cheers,
Eibe

From: Lorenzo Ferron <[email protected]>
Date: Thursday, 15 February 2024 at 9:55 AM
To: [email protected] <[email protected]>
Subject: [Wekalist] Why does `kNearestNeighbours` return more neighbours than `m_kNN` specified?
You don't often get email from [email protected]. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>

Dear WEKA Support Team,
I want to perform k-NN on Combined-Cycle Power Plant dataset<https://archive.ics.uci.edu/dataset/294/combined+cycle+power+plant>. I chose "Sheet 1", here<https://pastebin.com/raw/TH5uY094> you can find the CSV. The last column is the target.
How to reproduce my issue?

  1.  Load the dataset.
  2.  Choose as filter weka.filters.unsupervised.attribute.Standardize to standardize it.
  3.  Go to Classify tab.
  4.  Set Percentage split to 80%.
  5.  Click on More options... button.

     *   Enable Preserve order for % Split
     *   Paste weka.classifiers.evaluation.output.prediction.CSV -use-tab in Output predictions.

  1.  Paste weka.classifiers.lazy.IBk -K 4 -W 0 -E -A "weka.core.neighboursearch.LinearNNSearch -A \"weka.core.EuclideanDistance -D -R first-4\" -S" -output-debug-info as classifier.
  2.  Start the classification.

The second instance has a predicted value of 443.112. But KNeighborsRegressor from Scikit-Learn predicts 443.8775. I debugged WEKA and I discovered that m_NNSearch.kNearestNeighbours<https://git.cms.waikato.ac.nz/weka/weka/-/blob/3cbb52f2172daeab749aedd5afbe1463775ca361/trunk/weka/src/main/java/weka/classifiers/lazy/IBk.java#L585> sometimes returns 5 neighbours and not 4 even if m_kNN<https://git.cms.waikato.ac.nz/weka/weka/-/blob/3cbb52f2172daeab749aedd5afbe1463775ca361/trunk/weka/src/main/java/weka/classifiers/lazy/IBk.java#L132> is 4. But why? It seems that the size of m_Distances<https://git.cms.waikato.ac.nz/weka/weka/-/blob/3cbb52f2172daeab749aedd5afbe1463775ca361/trunk/weka/src/main/java/weka/core/neighboursearch/LinearNNSearch.java#L246> is sometimes 5 and not 4. Because heap.size()<https://git.cms.waikato.ac.nz/weka/weka/-/blob/3cbb52f2172daeab749aedd5afbe1463775ca361/trunk/weka/src/main/java/weka/core/neighboursearch/NearestNeighbourSearch.java#L80> is 4 while heap.noOfKthNearest()<https://git.cms.waikato.ac.nz/weka/weka/-/blob/3cbb52f2172daeab749aedd5afbe1463775ca361/trunk/weka/src/main/java/weka/core/neighboursearch/NearestNeighbourSearch.java#L160> is 1 and their sum is 5.

So this is right behaviour or not?

Kind regards,

Lorenzo

_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html