Computing the TF-IDF score

To actually compute the TF-IDF score for each word in each document, we first cache this tf RDD.

tf.cache() 

We do that because we're going to use it more than once. Next, we use IDF(minDocFreq=2), meaning that we're going to ignore any word that doesn't appear at least twice:

idf = IDF(minDocFreq=2).fit(tf) 

We call fit on tf, and then in the next line we call transform on tf:

tfidf = idf.transform(tf) 

What we end up with here is an RDD of the TF-IDF score for each word in each document.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.172.220