# How to scale new datas when a training set already exists

Here is what I have :

A scaled training set, with labels.

Segmented images, from which I extract new vectors to classify.

My classifier is a KNN which would have obviously been trained using my training set.

Now, I wonder how I should scale those new vectors I just got. Is this correct to scale them on their own, or should I do something else ? I wonder for example if an outlier would have an effect on the scaling and subsequent classification...

[EDIT] adding an outlier (which I would like to detect using kNN algorithm) to the test datas does impact the scaling, so subsequent classification won't work properly. What should I do then ?

[EDIT 2] This is how I scale my data :

Which in Scilab I translate to :

function dataout = scaledata(datain)

dataout = zeros(size(datain,1),size(datain,2));

for i=1:size(datain,2)
dataout(1:size(datain,1),i) = (datain(1:$,i) - min(datain(1:$,i))) / ...
(max(datain(1:$,i)) - min(datain(1:$,i)));
end

endfunction


Thank you

• How do you scaled your training data? Commented Mar 6, 2013 at 19:59

To maintain the same normalization of data you need to store the values ​​of min and max to apply on the new vectors. If you need to keep the coordinates of vectors within specific limits ($x \in [-1, 1]$, for example), it is necessary for min and max to be the limits that the coordinates can achieve (considering its domain), and not max and min of training data.

• If I understand well, it is about the same thing I thought of while waiting for an answer here : add new vectors to database, scale the whole thing, then take back the scaled new vectors and classify, feeding kNN with scaled new vectors as test datas and previously scaled (i.e. scaled without new vectors) database as training datas, correct ? Commented Mar 6, 2013 at 20:58
• You have to keep the max and min from training data. For example, if your min = -15 and max = 10 for the training data, you have the use then for the new values. Considering an sample from testing data, (x = 7), the scaled version is $\dfrac{7 - (-15)}{10 -(-15)}$. There is no update for min and max for the new vectors. They remain fixed for the whole testing data. Commented Mar 6, 2013 at 21:26
• Fair enough, I have some programming work ahead to implement and test this though. Could you please point to a source that explain all this ? Thank you !! Commented Mar 7, 2013 at 2:07
• This video may help: openclassroom.stanford.edu/MainFolder/… Commented Mar 7, 2013 at 17:28