TI-85 KNN Classifier

Not really a KNN Classifier, as much as a mass, N-dimension euclidean distance calculator.

Input is a Matrix MAT of all the points to test against (row-based), and a Vector X the point to test against. Output is a Nx1 matrix V of all the distances between X and each row of the Matrix (in order).

Prompt MAT,X
dim MAT->D
D(1)->N
D(2)->D
{N,1}->V
For(I,1,N,1)
MAT(I)->M
0->S
For(J,1,D,1)
(M(J)-X(J))2+S->S
End
√S->V(I,1)
End
Disp V

To test it out, run KNN. Enter:

MAT? [[1,1][1,2]]
X? [1,1]

This tests points (1,1) and (1,2) against the point (1,1). You should get [[0][1]] as a result.

Leave a Reply