AI summary by TwinMind

Cosine Similarity, Clearly Explained!!!

StatQuest with Josh Starmer

10m 13s

Introduction & Context

  • Josh Starmer presenting StatQuest educational video on cosine similarity
  • Sponsored by letters A, B, C (Always Be Curious motto)
  • Topic: cosine similarity metric for measuring text/document similarity

Problem Setup & Motivation

  • Example: analyzing sentences about 1990 movie Troll 2
  • First 3 sentences express positive feelings, last sentence negative
  • Easy to identify similarities manually with few sentences
  • Challenge: analyzing large datasets (e.g., month of Twitter traffic)
  • Need automated computer-based similarity measurement

Basic Cosine Similarity Concept

  • Cosine similarity: relatively easy metric to calculate similarity/difference
  • Measures angle between vectors in multi-dimensional space
  • Values range from 0 (completely different) to 1 (identical)

Simple Two-Word Example

  • Compare phrases: "hello world" vs "hello"
  • Step 1: Create word count table
    • "hello world": hello=1, world=1
    • "hello": hello=1, world=0
  • Step 2: Plot on 2D graph (hello on x-axis, world on y-axis)
    • "hello world" point at (1,1)
    • "hello" point at (1,0)
  • Step 3: Draw lines from origin (0,0) to each point
  • Step 4: Calculate angle between lines = 45 degrees
  • Cosine similarity = cos(45°) = 0.71

Key Properties of Cosine Similarity

  • Angle-dependent, not length-dependent
  • Example: "hello hello hello" vs "hello world"
    • Point moves to (3,0) but angle remains 45°
    • Cosine similarity still = 0.71
  • Identical phrases: angle = 0°, cosine similarity = 1
  • No common words: angle = 90°, cosine similarity = 0
  • Partial overlap: cosine similarity between 0 and 1

Mathematical Formula

  • Direct calculation formula provided (complex sigma notation)
  • Variables explained:
    • i = index (word position), starts at 1
    • n = total number of different words
    • A, B = the two phrases being compared
  • Example calculation yields 0.71 (matches geometric approach)

Multi-Dimensional Extension

  • Two words = 2D graph (feasible to visualize)
  • More words = higher dimensions (impossible to visualize)
  • Example: "I love Troll 2" vs "I love Gym Kata"
    • 5 different words = 5-dimensional space
    • Formula still works: cosine similarity = 0.58
  • Formula advantage: works regardless of dimensionality

Movie Reference

  • Gym Kata: 1985 movie about gymnast using parallel bars in Mortal Kombat

Promotional Content

  • StatQuest PDF study guides available
  • Book: "StatQuest Illustrated Guide to Machine Learning"
  • Available at statquest.org
  • Support options: Patreon, channel membership, merchandise, songs, donations

TwinMind

Get summaries like this for your own meetings

TwinMind takes notes in the background during meetings, lectures, and calls, then writes the summary for you.

Free plan to get started

No bot joins your calls

Phone, desktop & Chrome apps

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome