# Don’t Be a Dumb Computer: SVD Explained With a YouTube Recommender > How do YouTube, Netflix and Spotify know what you want before you do? I built a small recommender to find out. Here is Singular Value Decomposition worked through by hand, with real numbers. - Author: Yadunandan Singh (https://yadunandan-singh.pages.dev/) - Published: 2025-11-17 · updated 2026-10-19 - URL: https://yadunandan-singh.pages.dev/blog/svd-explained-youtube-recommender/ - Topics: Linear Algebra, Machine Learning, Recommender Systems - First published on Medium: https://medium.com/@yadunandan-ai-dev/dont-be-a-dumb-computer-svd-explained-subtitle-i-built-a-youtube-recommender-to-finally-155eabfbcbe6 ## Summary Yadunandan Singh explains Singular Value Decomposition by working a small example by hand: a 3 × 4 matrix of liked and disliked videos decomposes into concept strengths of 1.41, 0.92 and 0.20, and truncating to k = 2 keeps "STEM" and "entertainment" while discarding noise. He then shows how his YouTube recommender uses TF-IDF and scikit-learn's TruncatedSVD to place videos on that concept map, builds a taste profile as the average liked vector minus the average disliked one, and ranks candidates by cosine similarity. ## Key takeaways - SVD factors any matrix into U Σ Vᵀ: video-to-concept, concept strength, and concept-to-feature. - Keeping only the k strongest concepts (truncation) removes noise and makes the model faster. - TruncatedSVD.fit_transform returns U_k scaled by Σ_k: each item's coordinates on the concept map. - A taste profile is the average liked vector minus the average disliked vector. - Cosine similarity ranks candidates by how closely they point in the profile's direction. --- Have you ever wondered how YouTube, Netflix or Spotify know what you want to watch or hear next, without you ever telling them? It makes the experience feel almost effortless, and if you know anything about how computers work, you can guess what's underneath: maths. But not the dry, exam-paper kind. By the end of this post you'll know exactly which maths it is, you'll have worked through it by hand on a tiny example, and you'll see how a computer runs the same steps in a few lines of Python. I built a small [YouTube recommender](https://github.com/YADUNANDAN-SINGH/YouTube-video-recommendation-model-with-SVD) to understand it properly, and that's what we'll follow. ## The idea: describe videos with numbers Singular Value Decomposition (SVD) is the technique at the heart of many recommendation systems, and it starts with a single matrix. Let's build one by hand. Imagine describing videos with four features: how much each one is about **Physics**, **Maths**, **Vlogs** and **Funny** content. Here are three videos a viewer has rated: two they liked and one they hated. ```math Physics Maths Vlogs Funny Liked 1 [ 0.7 0.5 0.0 0.0 ] Liked 2 [ 0.7 0.9 0.0 0.0 ] Hated 1 [ 0.0 0.0 0.7 0.6 ] ``` This is our **matrix A**: 3 videos × 4 features, and the input to everything that follows. As humans, we see the pattern straight away. The two liked videos are both "STEM"; the hated one is "entertainment". We'd never recommend this person a vlog. The computer sees none of that. To it, these are just twelve numbers. It is a "dumb computer", and our job is to give it a method for finding the pattern itself. So let's understand the method first, and then teach it to the machine. ## The formula: A = U Σ Vᵀ SVD says that **any** matrix A can be broken into three special matrices: ```math A = U · Σ · Vᵀ ``` - **A** is what we *have*: the input data. - **U**, **Σ** and **Vᵀ** are what we *get*: three new matrices that describe the same data in a much more useful way. Geometrically, SVD describes any transformation as three simple moves: a rotation, a stretch along the axes, and another rotation. ![Three diagrams: a circle with axes, the same circle stretched into a wide ellipse, and a circle again in a new orientation.](https://yadunandan-singh.pages.dev/blog/svd-explained-youtube-recommender/svd-rotate-stretch-rotate.webp "SVD in pictures: rotate (Vᵀ), stretch (Σ), rotate again (U).") Reading the picture from left to right, start with a circle of points. **Vᵀ** rotates it, **Σ** stretches it into an ellipse (the "squeezed" one), and **U** rotates the result into its final position. We hand matrix A to the computer, tell it to run SVD, and it calculates the three matrices for us. Here's what comes back, and what each one means. ## 1. Σ: how strong each concept is **Σ** (often written S in code) is a list of *singular values*. Each one measures how important a hidden "concept" in the data is, and they always come sorted from strongest to weakest. For our matrix: ```math Σ = [ 1.41, 0.92, 0.20 ] │ │ └── concept 3: noise │ └────────── concept 2: "entertainment" └────────────────── concept 1: "STEM" ``` You can check this yourself in two lines of NumPy: ```python import numpy as np A = np.array([[0.7, 0.5, 0.0, 0.0], [0.7, 0.9, 0.0, 0.0], [0.0, 0.0, 0.7, 0.6]]) U, S, Vt = np.linalg.svd(A, full_matrices=False) print(S.round(2)) # [1.41 0.92 0.2 ] ``` This is the key result. It tells the computer that "STEM" (1.41) is the strongest pattern in the data, "entertainment" (0.92) is second, and the third concept (0.20) is weak. ## What is k, and why does it matter? **k is the number of concepts we decide to keep.** SVD found three, ranked by strength: 1. **Strength 1.41, "STEM".** The main pattern. 2. **Strength 0.92, "entertainment".** The second pattern. 3. **Strength 0.20, "noise".** Look at its recipe (the third row of Vᵀ) and you'll find it is roughly *Physics minus Maths*. It captures the one tiny difference between the two liked videos: one leans slightly more towards Physics, the other towards Maths. True, but irrelevant to what this person likes. So we have a choice: - **k = 3** keeps everything, including the noise. The computer can get distracted by details that don't matter. - **k = 1** keeps only "STEM". Too simple: the computer would know you like STEM, but not that you dislike entertainment. - **k = 2** is the sweet spot. Keep the two strong concepts and throw the noise away. Throwing away the weakest concepts is called **truncation**, which is why the code uses `TruncatedSVD`. It makes the system faster *and* smarter, because it forces the computer to focus on the big patterns rather than the noise. ## 2. Vᵀ: the recipe book **Vᵀ** tells us what each concept is made of. Its columns are our original features, and with k = 2 it has two rows, one recipe per concept: ```math Physics Maths Vlogs Funny Concept 1 [ 0.69 0.72 0.00 0.00 ] ← "STEM" Concept 2 [ 0.00 0.00 0.76 0.65 ] ← "entertainment" ``` Exactly what we'd hoped for. Concept 1 is roughly 0.7 × Physics + 0.7 × Maths; concept 2 is Vlogs plus Funny. One thing that trips everyone up: if you run this in NumPy, the first row may come back as `[-0.69, -0.72, 0, 0]`. That isn't a different answer. SVD can flip the sign of a concept as long as it flips the matching column of U too, and the product is identical. I've used the positive signs here because they're easier to read. ## 3. U: the video–concept map **U** says how much each **video** uses each **concept**. With 3 videos and k = 2 concepts, the truncated `U_k` is 3 × 2: ```math STEM Entertainment Liked 1 [ 0.60 0.00 ] Liked 2 [ 0.80 0.00 ] Hated 1 [ 0.00 1.00 ] ``` Now the computer can see what we saw at the start: both liked videos sit entirely on the STEM axis, and the hated video sits entirely on the entertainment axis. ## The "aha" moment: we don't need to rebuild A We went to all the trouble of computing A = U Σ Vᵀ, but for a recommender we **never multiply them back together**. What we want is a map. Every video becomes a point on a small, clean "subway map": instead of four messy features (Physics, Maths, Vlogs, Funny), each video is described by just two coordinates, STEM and entertainment. In my project, that's this line in `svd_engine.py`: ```python svd = TruncatedSVD(n_components=5) svd_matrix = svd.fit_transform(tfidf_matrix) ``` In the real project, matrix A isn't hand-written. It's built with TF-IDF from each video's title, description and tags, so it has thousands of word columns, and I keep k = 5 concepts. `fit_transform` runs the whole decomposition, keeps the k strongest concepts and returns each video's coordinates on the map. One precise detail: what it returns is `U_k` **scaled by the strengths** in Σ, so a stronger concept spreads the videos further apart. For our toy example the map coordinates are: ```math STEM Entertainment Liked 1 [ 0.85 0.00 ] 0.60 × 1.41 Liked 2 [ 1.13 0.00 ] 0.80 × 1.41 Hated 1 [ 0.00 0.92 ] 1.00 × 0.92 ``` That's how you teach a "dumb computer" to be smart. It doesn't learn what "STEM" means. It discovers that some features always move together, and puts them on a shared axis. ## Finding your taste with cosine similarity Every video is now a point on the map. Next, we need to find *you* on it. ### Step 1: Build a taste profile This is the part of `svd_engine.py` that turns ratings into a single vector: ```python avg_liked_video = np.mean(liked_svd_vectors, axis=0) avg_hated_video = np.mean(hated_svd_vectors, axis=0) profile = avg_liked_video - avg_hated_video ``` With our numbers: ```math average liked = ([0.85, 0.00] + [1.13, 0.00]) / 2 = [ 0.99, 0.00 ] average hated = [ 0.00, 0.92 ] profile = average liked − average hated = [ 0.99, −0.92 ] ``` This profile is your **taste compass**. It points strongly *towards* STEM (+0.99) and strongly *away from* entertainment (−0.92): subtracting what you hated pushes the compass in the opposite direction. ### Step 2: Measure with cosine similarity Now take two candidate videos: another STEM video (mostly Physics and Maths) and another vlog (mostly Vlogs and Funny). In my engine the candidates are rows of the same matrix, so they land on the map in the same `fit_transform` call. In the toy example, placing them on the map gives: ```math Candidate 1 (STEM) = [ 0.99, 0.00 ] Candidate 2 (vlog) = [ 0.07, 0.93 ] ``` **Cosine similarity** measures the angle between two vectors. It's a ruler, not a factory: it doesn't create anything new, it only measures how closely two directions agree, from +1 (same direction) to −1 (opposite). ```math similarity(profile, Candidate 1) = +0.73 similarity(profile, Candidate 2) = −0.62 ``` Why +0.73 rather than something closer to 1? Because the compass points towards STEM *and* away from entertainment, while the STEM candidate is simply neutral about entertainment. Close in direction, not identical. The vlog points almost exactly where you said you didn't want to go, so its score is strongly negative. The engine computes this score for every candidate, sorts them from highest to lowest, and the top of the list is your recommendation. **Candidate 1 wins.** ## The whole pipeline Put together, the recommender is five steps: ```text 1. Describe every video as numbers TF-IDF over titles, descriptions and tags 2. Find the hidden concepts TruncatedSVD, keeping the k strongest 3. Place every video on the map its coordinates along those k concepts 4. Build a taste profile average(liked) − average(hated) 5. Rank the candidates cosine similarity to the profile ``` The code that turns this maths into something a computer can run, along with a small Flask interface for trying it on real YouTube videos, is on [GitHub](https://github.com/YADUNANDAN-SINGH/YouTube-video-recommendation-model-with-SVD). If the geometry here felt shaky, the post where I built a [matrix transformation visualiser](https://yadunandan-singh.pages.dev/blog/linear-algebra-transformation-visualizer/) is the foundation this one sits on. And I later took the same idea further in [GlassBox](https://github.com/YADUNANDAN-SINGH/GlassBox-Rust-SVD-recommendation-system), which runs SVD entirely in the browser with Rust and WebAssembly.