To explain, lets say I am checking 9 nearest neighbors and doing classification on a handwritten digits dataset. First instance in test set has five nearest neighbors of class '4' and four neighbors of class '9'. Second test instance has eight neighbors of class '4' and one of class '9'. Obviously second test instance is classified as '4' with much greater certainty than the first one. How to express this with a function, and how to take distances into account?
I would also like to implement this to other classifiers. Any chance there is a C/C++ library with this functionality I could use, for any type of classifier?