0

I have two table namely Training_table and Testing table each contains two parameters of size say 100. I want to use k-NN for training using training_table and test the algorithm using 'Testing_table' values.

let us consider, In Training table

x = [4 5.5 6.5 8 9 10] ; y = [100 200 400 600 900 10000]

In Testing_table,

x1 = [7 8 9 ];  y1 = ?

So for given x1 value what is the estimated value for y1 ?

I have written code so far ,

testing_data = size(test_data,1);
training_data = size(training_data,1);

% absolute distance between all test and training data

dist = abs(repmat(testing_data,1,training_data) - repmat(training_data(:,1)',testing_data,1));

% indicies of nearest neighbors
[~,nearest] = sort(dist,2);
% k nearest
nearest = nearest(:,1:k);

% mode of k nearest
val = reshape(training_data(nearest,2),[],k);
out_data = mode(val,2);
% if mode is 1, output nearest instead
output(output==1) = val(output==1,1);

But it seems i am getting wrong. Could anyone suggest or advice on where I am making mistake ?

Ankita
  • 485
  • 5
  • 18

0 Answers0