<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Ask Ghassem - Recent questions tagged knn</title>
<link>https://ask.ghassem.com/tag/knn</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to perform a classification or regression using k-NN?</title>
<link>https://ask.ghassem.com/658/how-to-perform-a-classification-or-regression-using-k-nn</link>
<description>&lt;p&gt;Suppose, you have given the following dataset where x and y are the 2 features and color Red or Blue&amp;nbsp;is the target variable.&lt;/p&gt;

&lt;p&gt;a) A new&amp;nbsp;data point $x=1$ and $y=1$ is given. Using Euclidean distance in 3-NN, what you predict as the color for this data point?&lt;/p&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:300px; width:200px&quot;&gt;
&lt;caption&gt;Dataset&lt;/caption&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th scope=&quot;col&quot;&gt;x&lt;/th&gt;
&lt;th scope=&quot;col&quot;&gt;y&lt;/th&gt;
&lt;th scope=&quot;col&quot;&gt;Color&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Red&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Blue&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Red&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;Red&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Blue&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Blue&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Red&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Blue&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;b) Now assume we have the following dataset and the target value is the price.&amp;nbsp;A new&amp;nbsp;data point $x=1$ and $y=1$ is given. Using Euclidean distance in 3-NN. What would be the estimated price?&lt;/p&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:300px; width:200px&quot;&gt;
&lt;caption&gt;Dataset&lt;/caption&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th scope=&quot;col&quot;&gt;x&lt;/th&gt;
&lt;th scope=&quot;col&quot;&gt;y&lt;/th&gt;
&lt;th scope=&quot;col&quot;&gt;Price&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;$100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;$50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;$20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;$40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;$30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;$40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;$70&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;$30&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/658/how-to-perform-a-classification-or-regression-using-k-nn</guid>
<pubDate>Thu, 27 Jun 2019 02:54:42 +0000</pubDate>
</item>
<item>
<title>Calculate k nearest points using kNN for a single D array</title>
<link>https://ask.ghassem.com/241/calculate-k-nearest-points-using-knn-for-a-single-d-array</link>
<description>I am not able to figure out how the calculation of the $m$ nearest points will be in a single dimensional array using kNN. &amp;nbsp;Can anyone offer a clue or example?&lt;br /&gt;
Thank you</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/241/calculate-k-nearest-points-using-knn-for-a-single-d-array</guid>
<pubDate>Mon, 01 Oct 2018 21:50:03 +0000</pubDate>
</item>
<item>
<title>K Nearest Neighbor (KNN) - includes itself</title>
<link>https://ask.ghassem.com/240/k-nearest-neighbor-knn-includes-itself</link>
<description>&lt;h3&gt;The KNN function in the sklearn library (when coded properly), outputs the points closest to p based on the value of k, and others.&lt;/h3&gt;

&lt;p&gt;The point(s) would include itself when the code does not consider the point is in the data set.&lt;/p&gt;

&lt;p&gt;I included codes to exclude and include this occurrence.&lt;/p&gt;

&lt;p&gt;Is this acceptable?&lt;/p&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/240/k-nearest-neighbor-knn-includes-itself</guid>
<pubDate>Mon, 01 Oct 2018 21:35:01 +0000</pubDate>
</item>
<item>
<title>What happens as the K increases in the KNN algorithm ?</title>
<link>https://ask.ghassem.com/170/what-happens-asthe-k-increases-in-the-knn-algorithm</link>
<description>I am wondering what happens as K increases in the KNN algorithm. It seems that as K increases the &amp;quot;p&amp;quot; (new point) tends to move closer to the middle of the decision boundary?&lt;br /&gt;
&lt;br /&gt;
Any thoughts?</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/170/what-happens-asthe-k-increases-in-the-knn-algorithm</guid>
<pubDate>Fri, 28 Sep 2018 01:39:08 +0000</pubDate>
</item>
<item>
<title>How is KNN different from k-means clustering?</title>
<link>https://ask.ghassem.com/163/how-is-knn-different-from-k-means-clustering</link>
<description></description>
<category>Machine Learning Interview Questions</category>
<guid isPermaLink="true">https://ask.ghassem.com/163/how-is-knn-different-from-k-means-clustering</guid>
<pubDate>Thu, 27 Sep 2018 05:25:34 +0000</pubDate>
</item>
<item>
<title>Is normalization necessary in all KNN algorithms? (Python)</title>
<link>https://ask.ghassem.com/161/is-normalization-necessary-in-all-knn-algorithms-python</link>
<description>&lt;p&gt;I have read online articles involving KNN and its emphasis on normalization. I would like to know if all KNN functions in Python need to involve normalization?&amp;nbsp;&lt;/p&gt;

&lt;p&gt;I do know that normalization computes values that are usually between 0 and 1 but would this process be necessary in all python KNN functions or is it specific to certain scenarios?&lt;/p&gt;

&lt;p&gt;When dealing with distance, L1 or L2, would normalization be needed?&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(a few) Blogs / Articles:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://stats.stackexchange.com/questions/287425/why-do-you-need-to-scale-data-in-knn&quot;&gt;Stack Exchange&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://stackoverflow.com/questions/42092448/accuracy-difference-on-normalization-in-knn&quot;&gt;Stack OverFlow&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://discuss.analyticsvidhya.com/t/why-it-is-necessary-to-normalize-in-knn/2715&quot;&gt;Vidyha Analytics&lt;/a&gt;&lt;/p&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/161/is-normalization-necessary-in-all-knn-algorithms-python</guid>
<pubDate>Thu, 27 Sep 2018 01:06:02 +0000</pubDate>
</item>
</channel>
</rss>