Answers.Body: <p>This is a rather involved task. What to do from a high-level theoretical perspective might be easy to see, but it's difficult putting that into code from scratch.</p>
  <p>Doing this in Python using existing libraries in not too complicated, though.
  See for example this <a href="https://pythonspot.com/k-nearest-neighbors/" rel="nofollow noreferrer">tutorial</a> or this <a href="https://stackoverflow.com/a/52407052/11478452">StackOverflow post</a>.</p>
  <p><strong>Edit:</strong></p>
  <p>Theoretically, I would first plot (draw) the points from your dataset in a graph and then watch out for &quot;decision points&quot; half-way <em>in between any two near-by points (from the dataset) from distinct classes</em>.</p>
  <p>For the next step, keep in mind those decision points. Given close-by data points from classes (e.g.) <em>A</em> and <em>B</em>, <em>imagine a straight line connecting these two points from separate classes</em>. Next, take the point half-way along that imaginary line (i.e. your decision point) and draw a &quot;soft&quot; line (maybe using pencil instead of pen) orthogonal/perpendicular to that imaginary line which intersects the imaginary line in the decision point.
  Do that for all combinations of &quot;reasonably&quot; close points from different classes.</p>
  <p>Parts of the lines you have just drawn will define the final decision boundary. Next, think of each line as consisting of multiple elements, which are separated from one another by means of the points of intersection with other drawn lines. In other words, split lines into elements wherever they intersect other lines. Now, decide which of these elements to outline as the eventual decision boundary (finally using a <strong>pen</strong> instead of pencil). This step simply involves human intelligence and is difficult to describe. Whenever a line's element accurately separates (logically speaking) two classes, indicate it using a pen. Otherwise, if it does not contribute to separating two classes, don't indicate it.</p>
  <p>After having indicated the final decision boundary using a pen, simply erase the pencil drawings. Now, you should be left with a decision boundary.</p>
  <p>I hope this is clear and accurate enough.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-30T18:05:03.613Z
Answers.Text: The question is come from a old exam. So the decision boundaries can be drawn by hand. I am not even sure how to do it
Answers.UserDisplayName: David
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-30T19:18:44.827Z
Answers.Text: Yes, I realized and corrected that already. I went through a few examples and encountered problems with the previous proposal indeed.
Answers.UserDisplayName: Daniel B.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-30T19:26:27.650Z
Answers.Text: ok now, thus I delete my answer. Hint: think about the problem as if each point was an independent class. After draw the perpendiculars, each point is enclosed by a convex polygon formed by these perperndiculars. This is the area the point "owns". Latter, just paint of same color the areas of points with same labels.
Answers.UserDisplayName: pasaba por aqui
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-30T18:00:13.643Z
Answers.LastActivityDate: 2020-10-30T19:16:18.983Z
Answers.LastEditDate: 2020-10-30T19:16:18.983Z
Answers.UserDisplayName: Daniel B.
Body: <p>How to manually draw  a <span class="math-container">$k$</span>-NN decision boundary with <span class="math-container">$k=1$</span> knowing the dataset</p>
  <p><a href="https://i.sstatic.net/n6TBy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/n6TBy.png" alt="enter image description here" /></a></p>
  <p>the labels are</p>
  <p><a href="https://i.sstatic.net/ONnUN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ONnUN.png" alt="enter image description here" /></a></p>
  <p>and the euclidean distance between two points is defined as</p>
  <p><a href="https://i.sstatic.net/L0gm8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/L0gm8.png" alt="enter image description here" /></a></p>
  
Tags: <machine-learning><k-nearest-neighbors>
Title: How to manually draw a $k$-NN decision boundary with $k=1$ given the dataset and labels?
UserDisplayName: David
ThreadText: # How to manually draw a $k$-NN decision boundary with $k=1$ given the dataset and labels?
  
  (Asked by: username_0 on 2020-10-30)
  
  How to manually draw a $k$-NN decision boundary with $k=1$ knowing the dataset
  
  [![enter image description here](https://i.sstatic.net/n6TBy.png)](https://i.sstatic.net/n6TBy.png)
  
  the labels are
  
  [![enter image description here](https://i.sstatic.net/ONnUN.png)](https://i.sstatic.net/ONnUN.png)
  
  and the euclidean distance between two points is defined as
  
  [![enter image description here](https://i.sstatic.net/L0gm8.png)](https://i.sstatic.net/L0gm8.png)
  
  **Tags:** machine-learning, k-nearest-neighbors
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-30. Score: 1 | Accepted answer
  
  This is a rather involved task. What to do from a high-level theoretical perspective might be easy to see, but it's difficult putting that into code from scratch.
  
  Doing this in Python using existing libraries in not too complicated, though.
  See for example this [tutorial](https://pythonspot.com/k-nearest-neighbors/) or this [StackOverflow post](https://stackoverflow.com/a/52407052/11478452).
  
  **Edit:**
  
  Theoretically, I would first plot (draw) the points from your dataset in a graph and then watch out for "decision points" half-way *in between any two near-by points (from the dataset) from distinct classes*.
  
  For the next step, keep in mind those decision points. Given close-by data points from classes (e.g.) *A* and *B*, *imagine a straight line connecting these two points from separate classes*. Next, take the point half-way along that imaginary line (i.e. your decision point) and draw a "soft" line (maybe using pencil instead of pen) orthogonal/perpendicular to that imaginary line which intersects the imaginary line in the decision point.
  Do that for all combinations of "reasonably" close points from different classes.
  
  Parts of the lines you have just drawn will define the final decision boundary. Next, think of each line as consisting of multiple elements, which are separated from one another by means of the points of intersection with other drawn lines. In other words, split lines into elements wherever they intersect other lines. Now, decide which of these elements to outline as the eventual decision boundary (finally using a **pen** instead of pencil). This step simply involves human intelligence and is difficult to describe. Whenever a line's element accurately separates (logically speaking) two classes, indicate it using a pen. Otherwise, if it does not contribute to separating two classes, don't indicate it.
  
  After having indicated the final decision boundary using a pen, simply erase the pencil drawings. Now, you should be left with a decision boundary.
  
  I hope this is clear and accurate enough.
  
  > **Comments:**
  > **username_0**: The question is come from a old exam. So the decision boundaries can be drawn by hand. I am not even sure how to do it  
  > **username_1**: Yes, I realized and corrected that already. I went through a few examples and encountered problems with the previous proposal indeed.  
  > **username_2**: ok now, thus I delete my answer. Hint: think about the problem as if each point was an independent class. After draw the perpendiculars, each point is enclosed by a convex polygon formed by these perperndiculars. This is the area the point "owns". Latter, just paint of same color the areas of points with same labels.  
  
  ---
  
  