Text Analytics with Python by Dipanjan Sarkar

Text Analytics with Python by Dipanjan Sarkar

Author:Dipanjan Sarkar
Language: eng
Format: epub, pdf
Publisher: Apress, Berkeley, CA


def tfidf_transformer(bow_matrix):

transformer = TfidfTransformer(norm='l2',

smooth_idf=True,

use_idf=True)

tfidf_matrix = transformer.fit_transform(bow_matrix)

return transformer, tfidf_matrix

You can see that we have used the L2 norm option in the parameters and also made sure we smoothen the idfs to give weightages also to terms that may have zero idf so that we do not ignore them. We can see this function in action in the following code snippet:

import numpy as np

from feature_extractors import tfidf_transformer

feature_names = bow_vectorizer.get_feature_names()



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.