function [predictedValue] = OneNN(myRow, dataset, currentPreProcessor)

% this function finds the closest instance
% then returns the predicted value

featureSize = size(dataset,2);

if strcmp(currentPreProcessor, 'normalize') ~= 1 && strcmp(currentPreProcessor, 'log') ~= 1
    % firstly normalize the row and data
    myTempToNormalize = [myRow;dataset];
    myTempToNormalize = myNormalizer(myTempToNormalize);
    % get normalized train data and replace cost with actual cost
    myRow = myTempToNormalize(1,:);     % store normalized test data
    myTempToNormalize(1,:) = []; % delete test data
    dataset = myTempToNormalize;
end

% initially let the first instance have the best distance
bestDist = sqrt(sum(abs(myRow(1,1:(featureSize-1)) - dataset(1,1:1:(featureSize-1))).^2));
bestIndex = 1;

% check other instances for being closest
for i=2:size(dataset,1)
    tempDist = sqrt(sum(abs(myRow(1,1:1:(featureSize-1)) - dataset(i,1:1:(featureSize-1))).^2));
    if tempDist < bestDist
        bestDist = tempDist;
        bestIndex = i;
    end
end

% save the effort value of the closest neighbor
predictedValue = dataset(bestIndex,featureSize);

end