1

I am using a Knn classifier in MATLAB. Here is my Code:

load fisheriris
x = meas(:,3:4);

newpoint = [5 1.45];

[n,d] = knnsearch(x,newpoint,'k',10, 'Distance', 'euclidean');

Now I would like to use my own distance function. To be sure, that it is working, I first would like to define my "own" Euclidean distance. After that I would like to try the ChiSquare Distance.

My problem: How can I create my own distance function. I know I should use pdist(), but I am not able to get it working. Would be great to get some hints.

chappjc
  • 30,359
  • 6
  • 75
  • 132
user2576458
  • 161
  • 3
  • 9
  • This is pretty self-explanatory. I do not have MATLAB access to write a short code. From MATLAB documentation [here](http://www.mathworks.com/help/stats/knnsearch.html)`custom distance function — A distance function specified using @ (for example, @distfun). A distance function must be of the form function D2 = distfun(ZI, ZJ), taking as arguments a 1-by-n vector ZI containing a single row of X or Y, an m2-by-n matrix ZJ containing multiple rows of X or Y, and returning an m2-by-1 vector of distances D2, whose jth element is the distance between the observations ZI and ZJ(j,:).` – Autonomous Jan 28 '14 at 16:57
  • try it and if you have problems then post it here. – Autonomous Jan 28 '14 at 16:58

0 Answers0