Algorithm for the best classification of vectors

Given the four binary vectors that represent the "classes":

[1,0,0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0,1] [0,1,1,1,1,1,1,1,1,0] [0,1,0,0,0,0,0,0,0,0] 

What methods are available for classifying a vector of floating point values ​​in one of these "classes"?

The main rounding works in most cases:

 round([0.8,0,0,0,0.3,0,0.1,0,0,0]) = [1 0 0 0 0 0 0 0 0 0] 

But how can I handle some interference?

 round([0.8,0,0,0,0.6,0,0.1,0,0,0]) != [1 0 0 0 0 1 0 0 0 0] 

This second case should be the best match for 1,000,000,000, but instead I completely lost the solution as there is no clear match.

I want to use MATLAB for this task.

+4
source share
3 answers

Find the SSD (sum of squared differences) of your test vector with each "class" and use the one that has the smallest SSD.

Here is some code: I added 0 to the end of the test vector, which you indicated, since it was only 9 digits, while the classes had 10.

 CLASSES = [1,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,1 0,1,1,1,1,1,1,1,1,0 0,1,0,0,0,0,0,0,0,0]; TEST = [0.8,0,0,0,0.6,0,0.1,0,0,0]; % Find the difference between the TEST vector and each row in CLASSES difference = bsxfun(@minus,CLASSES,TEST); % Class differences class_diff = sum(difference.^2,2); % Store the row index of the vector with the minimum difference from TEST [val CLASS_ID] = min(class_diff); % Display disp(CLASSES(CLASS_ID,:)) 

As an illustration, the difference as follows:

  0.2 0 0 0 -0.6 0 -0.1 0 0 0 -0.8 0 0 0 -0.6 0 -0.1 0 0 1 -0.8 1 1 1 0.4 1 0.9 1 1 0 -0.8 1 0 0 -0.6 0 -0.1 0 0 0 

And the distance of each class from TEST looks like this: class_diff :

  0.41 2.01 7.61 2.01 

And, obviously, the first is the best match, because it has the smallest difference.

+5
source

This is the same as Jacob , with only four different distance measurements:


 %% CLASSES = [1,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,1 0,1,1,1,1,1,1,1,1,0 0,1,0,0,0,0,0,0,0,0]; TEST = [0.8,0,0,0,0.6,0,0.1,0,0,0]; %% % sqrt( sum((xy).^2) ) euclidean = sqrt( sum(bsxfun(@minus,CLASSES,TEST).^2, 2) ); % sum( |xy| ) cityblock = sum(abs(bsxfun(@minus,CLASSES,TEST)), 2); % 1 - dot(x,y)/(sqrt(dot(x,x))*sqrt(dot(y,y))) cosine = 1 - ( CLASSES*TEST' ./ (norm(TEST)*sqrt(sum(CLASSES.^2,2))) ); % max( |xy| ) chebychev = max( abs(bsxfun(@minus,CLASSES,TEST)), [], 2 ); dist = [euclidean cityblock cosine chebychev]; %% [minDist classIdx] = min(dist); 

Choose the one you like :)

+2
source

A simple simple Euclidean algorithm is enough. A class with a minimum distance to a point will be your candidate.

http://en.wikipedia.org/wiki/Euclidean_distance

+1
source