July 2017
Beginner to intermediate
420 pages
10h 56m
English
Let's try and put the algorithm to use. Let's try to look up the best article for the word Gettysburg. If you're not familiar with US history, that's where Abraham Lincoln gave a famous speech. So, we can transform the word Gettysburg into its hash value using the following code:
gettysburgTF = hashingTF.transform(["Gettysburg"]) gettysburgHashValue = int(gettysburgTF.indices[0])
We will then extract the TF-IDF score for that hash value into a new RDD for each document:
gettysburgRelevance = tfidf.map(lambda x: x[gettysburgHashValue])
What this does is extract the TF-IDF score for Gettysburg, from the hash value it maps to for every document, and stores that in this gettysburgRelevance RDD. ...
Read now
Unlock full access