Consider a vector (single query point) `xnew`

and a model
`mdl`

.

*k* is the number of
nearest neighbors used in prediction,
`mdl.NumNeighbors`

.

`nbd(mdl,xnew)`

specifies the
*k* nearest neighbors to
`xnew`

in
`mdl.X`

.

`Y(nbd)`

specifies the classifications of the
points in `nbd(mdl,xnew)`

, namely
`mdl.Y(nbd)`

.

`W(nbd)`

specifies the weights of the points in
`nbd(mdl,xnew)`

.

`prior`

specifies the
priors of the classes in
`mdl.Y`

.

If the model contains a vector of prior probabilities, then the observation weights
`W`

are normalized by class to sum to the priors.
This process might involve a calculation for the point `xnew`

,
because weights can depend on the distance from `xnew`

to the
points in `mdl.X`

.

The posterior probability *p*(*j*|`xnew`

)
is

Here, $${1}_{Y(X(i))=j}$$ is `1`

when
`mdl.Y(i) = j`

, and
`0`

otherwise.