Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 08

Dimensionality Reduction

Nine beginner steps on six students: study and practice hours share one line that keeps about 94 percent of their spread.

Beginner22 min
Scatter of six students. Study and practice hours rise together along one line. A is 2 and 2, F is 7 and 7.
Ten student measurements compressed into two new mixed columns

You want to predict exam marks. Before any model, someone collects a row for each student:

Field One student
Study hours 5
Attendance 85%
Assignment score 90
Sleep hours 7
Previous marks 75
Screen time 3 hours
Class participation 80
Practice tests 5
Revision hours 2
Notes completion 90%

Ten numbers already. A hospital row or a photo can have hundreds. Some numbers repeat each other. Some are almost noise.

Dimensionality reduction makes a shorter row that still carries the useful pattern.

The short row is often a mix, not a shortlist. Keeping "study hours" and throwing the rest away is feature selection. PCA does feature extraction: it builds new columns from the old ones.

This page draws only two of the ten, because two numbers fit on a chart. Study hours and practice hours for six students:

Student Study Practice
A 2 2
B 3 4
C 4 3
D 5 6
E 6 5
F 7 7

The average of each column is 4.5. A and F sit on the line "practice = study". B and D practice a little more than they study. C and E do the opposite.

2. Types of dimensionality reduction

Number line of the first new column: B and C share -1.4, D and E share 1.4, A is -3.5 and F is 3.5
Method What it makes On this page
PCA New columns along the widest spread. No pass or fail label is used. The line through these six students
LDA A direction that separates classes you already know, such as pass and fail Uses the exam label. PCA does not.
t-SNE A picture of who sits near whom For looking, not for the column a later model must reuse
UMAP Another picture of neighborhoods, often steadier when you add a new student Same job as t-SNE: a map
Autoencoder A network that squeezes the row, then tries to rebuild the original numbers The squeeze is the short row

Two different cuts:

  • Selection keeps original names. "Keep study hours, drop practice hours."
  • Extraction builds a new number. PCA does this.

If you keep only the line, B and C land on the same new number, −1.4. One practiced more, one studied more, and the single line forgot that difference. That is the price of the shorter row.

3. Where is it used?

Bars: 10 student fields collected, 2 drawn, and 1 kept when the sideways 6 percent is dropped
Job Why the row is wide
Student marks The ten fields above. This lesson.
Photos Hundreds of pixel values for one face
A clinic Hundreds of measurements on one person
Markets Many indicators on one day
Customers Many clicks and purchases on one person
Text A long list of word scores for one sentence
Genes Thousands of measurements on one sample

The method is a preparation step. A later model, such as a line or a support vector machine, then predicts pass or fail from the short row. A tree model can often keep the original ten and does not need this squeeze.

4. Which algorithms use it?

Bar chart: about 94 percent of the spread is along the line and about 6 percent is sideways
Name Role
PCA The straight-line mix. These six students.
Kernel PCA A bend, when a straight line cannot follow the cloud
Truncated SVD The same family of mixes, often on huge sparse text tables
t-SNE A 2D picture
UMAP A 2D picture that also places a new point more calmly
LDA A mix that uses the class label
Autoencoder A learned squeeze and rebuild

On these six students the shares are exact enough to say in class. Square the along-the-line positions and add them: 33. Square the sideways leftovers and add them: 2. Together 35. The line holds 33 / 35, about 94%. The sideways piece is about 6%.

A pipeline, when you do use it:

  1. Clean the table.
  2. Put columns on a similar scale when the units differ. These two columns are both hours, so the picture did not need that.
  3. Fit the direction on the training students only. A new student is dropped onto that same line. Do not refit the line using the student you are scoring.
  4. Then predict.

5. What problems does a wide table face?

Line chart: study hours per week are exactly 7 times study hours per day

The row gets lonely. With ten or a hundred columns, students stop looking "near" each other in a way you can trust. Distance becomes a weak guide. People call this the curse of dimensionality. Two hours, as on the chart, are still easy to see.

Copies. Study hours per day and study hours per week are the same news. Per week is per day times 7. A is 2 and 14. F is 7 and 49. Storing both does not add a second fact. Revision hours can be a third copy of the same habit.

Noise. A column such as "lucky pen number" jitters without tracking study. It makes the cloud fuzzier.

Cost. More columns mean more memory and, for some models, a slower fit.

You cannot plot ten axes. The chart on this page exists because we kept two.

6. How one line replaces two scores

Each student dropped onto the line. B and C land together at 3.5 hours. Their new column is -1.4.

Center the hours by subtracting 4.5.

Along the line = (study + practice − 9) / √2

√2 is about 1.414. The direction of the line is equal parts study and practice, about 0.707 each. That pair of weights is the first principal component.

Student Study Practice Along the line Sideways
A 2 2 (4 − 9) / 1.414 ≈ −3.5 0
B 3 4 (7 − 9) / 1.414 ≈ −1.4 (4 − 3) / 1.414 ≈ 0.7
C 4 3 −1.4 −0.7
D 5 6 1.4 0.7
E 6 5 1.4 −0.7
F 7 7 (14 − 9) / 1.414 ≈ 3.5 0

Sideways = (practice − study) / √2. It is the second component, at a right angle to the line.

Drop B onto the line and both hours come back as 3.5. The real row was 3 and 4. The missing half hour each way is the sideways 0.7. If you keep both new columns, you can rebuild 3 and 4. If you keep only the line, B and C look identical.

In symbols, for a wider table: take the centered row, and multiply by the direction. The result is the new short row. For these two hours the direction is (0.707, 0.707), and the result is the "along the line" column.

Stacked bar: a sample report with 85 percent, 10 percent, and 5 percent. The first two add to 95.

Read a report on all ten fields the same way. Suppose it says the first new column holds 85% of the spread, the second 10%, and the rest 5%. Keeping two columns keeps 85 + 10 = 95% of the spread.

That 95% is spread, not exam accuracy. A column can vary a lot and still be useless for predicting marks. PCA does not look at the mark.

Five habits that avoid the usual mistakes:

  • Do not squeeze every table. Trees often prefer the original columns.
  • Scale columns when one is hours and another is a percent or a rupee amount. The huge unit would otherwise own the line.
  • Fit the line on training students. Apply that frozen line to anyone new.
  • Do not read "95% of the spread" as "95% of the predictions will be right."
  • A t-SNE or UMAP picture is a view. It is not proof that the groups exist as neat clusters in the original ten columns.

7. Key Takeaways

  • The aim is a shorter row that keeps the pattern, not a longer one.
  • Selection keeps old names. Extraction, including PCA, builds new mixes.
  • PCA does not use the pass or fail label. LDA does.
  • On these six students the line holds about 94% of the spread. A and F are −3.5 and 3.5. B and C share −1.4.
  • t-SNE and UMAP are mainly pictures. An autoencoder learns a squeeze.
  • 85 + 10 = 95 is how you add a variance report. It is not an accuracy score.
  • Fit the direction on the training rows only.

8. Mind Map

Memory chart of the six students on the study-versus-practice line

A is 2 and 2, which is −3.5 on the line. F is 7 and 7, which is 3.5. If those two still come from (study + practice − 9) / 1.414, the page is yours.

9. Quiz

The questions use this story: ten fields squeezed to mixes, the six students on the line, and a report of 85% and 10%.

Check your understanding

Dimensionality Reduction Quiz

What is the goal of PCA?

1 / 10