influences the number of features and the performance rescaling the data with tf-idf instead of dropping features that are deemed unimportantanother approach is to rescale features by how informative we expect them to be one of the most common ways to do this is using the term frequency-inverse document frequency (tf-idfmethod the intuition of this method is to give high weight to any term that appears often in particular documentbut not in many documents in the corpus if word appears often in particular documentbut not in very many documentsit is likely to be very descriptive of the content of that document scikit-learn implements the tf-idf method in two classestfidftransformerwhich takes in the sparse matrix output produced by countvectorizer and transforms itand tfidfvectorizerwhich takes in the text data and does both the bag-of-words feature extraction and the tf-idf transformation there are several variants of the tf-idf rescaling schemewhich you can read about on wikipedia the tf-idf score for word in document as implemented in both the tfidftransformer and tfidfvectorizer classes is given by: tfidf wd tf log + + nw where is the number of documents in the training setnw is the number of documents in the training set that the word appears inand tf (the term frequencyis the number of times that the word appears in the query document (the document you want to transform or encodeboth classes also apply normalization after computing the tf-idf representationin other wordsthey rescale the representation of each document to have euclidean norm rescaling in this way means that the length of document (the number of wordsdoes not change the vectorized representation because tf-idf actually makes use of the statistical properties of the training datawe will use pipelineas described in to ensure the results of our grid search are valid this leads to the following code we provide this formula here mostly for completenessyou don' need to remember it to use the tf-idf encoding working with text data