Yes you need to apply normalisation to test data, if your algorithm works with or needs normalised training data*.
That is because your model works on the representation given by its input vectors. The scale of those numbers is part of the representation. This is a bit like converting between feet and metres . . . a model or formula would work with just one type of unit normally.
Not only do you need normalisation, but you should apply the exact same scaling as for your training data. That means storing the scale and offset used with your training data, and using that again. A common beginner mistake is to separately normalise your train and test data.
In Python and SKLearn, you might normalise your input/X values using the Standard Scaler like this:
scaler = StandardScaler()
train_X = scaler.fit_transform( train_X )
test_X = scaler.transform( test_X )
Note how the conversion of train_X
using a function which fits (figures out the params) then normalises. Whilst the test_X
conversion just transforms, using the same params that it learned from the train data.
The tf-idf normalisation you are applying should work similarly, as it learns some parameters from the data set as a whole (frequency of words in all documents), as well as using ratios found in each document.
* Some algorithms (such as those based on decision trees) do not need normalised inputs, and can cope with features that have different inherent scales.