O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Analyzing the tf-idf weightings

Next, let's investigate the tf-idf weighting for a few terms to illustrate the impact of the commonality or rarity of a term.

First, we can compute the minimum and maximum tf-idf weights across the entire corpus:

val minMaxVals = tfidf.map { v =>   val sv = v.asInstanceOf[SV]   (sv.values.min, sv.values.max) } val globalMinMax = minMaxVals.reduce { case ((min1, max1),   (min2, max2)) =>   (math.min(min1, min2), math.max(max1, max2)) } println(globalMinMax)

As we can see, the minimum tf-idf is zero, while the maximum is significantly larger:

(0.0,66155.39470409753)

We will now explore the tf-idf weight attached to various terms. In the previous section on stop words, we filtered out many common terms that occur ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required