Boundary decision with knn-classifier
<p>I want to find the boundary-decision function in order to classify my data. Here is an example of them.  </p>

<pre><code> "Distance","Dihedral","Categ"
    4.083,82.267,C
    4.132,87.073,C
    4.713,-80.999,C
    3.427,-48.144,NC
    3.663,96.994,C
    3.99,71.919,C
    3.484,78.684,C
</code></pre>

<p>So far I've got the knn model but I'd like to plot the non-linear decision boundary. In the examples I have searched, there are some variables that I don't have a clue where to use them or what do they mean. I'm talking about this example I found in "The Elements of Statistical Learning" book</p>

<pre><code>library(ElemStatLearn)
require(class)
x &lt;- mixture.example$x
g &lt;- mixture.example$y
xnew &lt;- mixture.example$xnew
mod15 &lt;- knn(x, xnew, g, k=15, prob=TRUE)
prob &lt;- attr(mod15, "prob")
prob &lt;- ifelse(mod15=="1", prob, 1-prob)
px1 &lt;- mixture.example$px1
px2 &lt;- mixture.example$px2
prob15 &lt;- matrix(prob, length(px1), length(px2))
par(mar=rep(2,4))
contour(px1, px2, prob15, levels=0.5, labels="", xlab="", ylab="", main=
        "15-nearest neighbour", axes=FALSE)
points(x, col=ifelse(g==1, "coral", "cornflowerblue"))
gd &lt;- expand.grid(x=px1, y=px2)
points(gd, pch=".", cex=1.2, col=ifelse(prob15&gt;0.5, "coral", "cornflowerblue"))
box()
</code></pre>

<p>What exactly are px1 and px2? Do I need similar variables for my particular case?</p>

<p>Thank you very much for your help!</p>