← Course overview

Oct. 9 · Cosine similarity and hierarchical clustering, with k-means shown

Session 4 · Clustering and Similarity

Clustering groups documents by measured similarity. Interpreting those groups still requires reading the texts.

Objective

By the end of class, you can compare documents by vocabulary, group them with hierarchical clustering, and explain how k-means differs.

Before class

Optional, if you want to get ahead

See all R-foundation deadlines and marks →

What you bring from Session 3

Your Demo 3 workflow, which ends with a Bag of Words after Preprocess Text. Session 4 starts from it. Save a copy as your Demo 4 workflow before you change anything.

Session 4 uses a larger file, presidential-speeches-300.csv. It holds the 100 speeches you know plus 200 more, so that each president has 100 (corpus card). You preprocess it yourself, as in Session 2. Your groups can differ a little from the slides, because Kiwi versions split some words differently. That is expected.

What this session is about

Session 3 asked which words set one speech apart. Session 4 asks which speeches are alike, and groups them.

The computer finds the groups. It does not say what they mean. You decide that by reading speeches from each group and using what you know about the data and the topic.

To review these ideas, watch the explainer video (new tab, 6.5 minutes). It walks through the 300 speeches, cosine similarity and distance, and hierarchical clustering, with the same numbers as the slides.

Laptop demonstration

Files for today Save the files in the data/ folder of your course repository.

Standard track · Orange

Extend your Demo 3 workflow. In the File widget, open presidential-speeches-300.csv instead of the 100-speech file. The Python Script and Preprocess Text then run on all 300 speeches, which takes a few minutes. Then add the clustering chain after your TF-IDF Bag of Words.

Bag of Words → Select Columns → Distances → Hierarchical Clustering

Connect at least two of Pivot Table, Distributions, and Select Rows with Word Cloud to Hierarchical Clustering. The settings for each widget are on the slides. k-means is optional.

BA2 review track · R

Complete this assignment in R. Orange is not permitted for assessed work. You preprocess the 300 speeches with your Session 2 script and then follow the steps from Session 3. You cluster the speeches, save a dendrogram and at least two more figures or tables, and write the README.

Demo 4 · Cluster and inspect documents

Due Oct. 16 at 09:15

Create demos/04-clustering/ with the following files.

Writing the README

Before you submit