For this condition, if your data set is large enough, you can only use the training set for IDF. at the testing stage, if the new term in the train set uses the IDF for training, and if this term is new, use the number of documents for the train set to calculate the IDF. For some purposes, you can use anti-aliasing techniques to get better results.
source
share