# How to create function that classifies sample data

I want to create expression, that classifies samples ( 4 weather features -> decision).

Example training data:

For the values that i have data for, I can use rules:

fs = {
{0, 0, 0, 0} -> 1, {2, 1, 0, 0} -> 1, {2, 2, 1, 0} -> 1, {0, 2, 1, 1} -> 1,
{1, 2, 1, 0} -> 1, {2, 1, 1, 0} -> 1, {1, 1, 1, 1} -> 1, {0, 1, 0, 1} -> 1,
{0, 0, 1, 0} -> 1, {1, 0, 0, 0} -> 0, {1, 0, 0, 1} -> 0, {2, 2, 1, 1} -> 0,
{1, 1, 0, 0} -> 0, {2, 1, 0, 1} -> 0};
{2, 1, 0, 1} /. fs


Alternatively I can use table/hashmap:

fs[{0, 0, 0, 0}] = 1;
fs[{2, 1, 0, 0}] = 1;
(*etc.*)
fs[{2, 1, 0, 1}]


How can I compute an estimation decision based on closest* existing sample element(s)?

closeness can be defined by any distance function ex: {euclidean distance,hamming distance,...}.

-
I don't know that I understand your application but can you not use a list of replacement rules directly? –  Mr.Wizard Oct 22 '12 at 22:44
Tally of the feature vectors shows the sample values are unique, so there exist one (or more) functions into the decision space. However, n=14 whereas there are 3*3*2*2=36 presumably possible values of feature vectors - so it's necessary to specify a loss function b/c it is the generalization on unseen data that matters. Otherwise, as Mr.Wizard states, just use example rules directly. –  alancalvitti Oct 22 '12 at 23:48
You mention a decision tree, were you thinking of C4.5 or CART type decision trees ? –  image_doctor Oct 27 '12 at 9:45

If I understood correctly, just do, using your fs

classify=Nearest[fs];


or eventually

classify=Nearest[fs, DistanceFunction->distFun]


where distFun can be EuclideanDistance, HammingDistance, .... Then you just do

classify[data]