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.