0Pricing
Data Science Academy · Lesson

Choose Components With Scree Plots

Keeping enough explained variance.

Choose Components With Scree Plots is a free Data Science Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

How Many to Keep?

PCA can hand you dozens of components, but you only want the useful few. The real skill is choosing how many to keep.

Meet the Scree Plot

A scree plot charts each component against the variance it explains, so you can see importance drop off at a glance.

Look for the Elbow

Variance falls fast then levels into a flat tail. The bend, called the elbow, marks where extra components stop paying off.

Plot the Ratios

Fit PCA with all components, then plot explained_variance_ratio_ to draw the curve and spot that elbow.

import matplotlib.pyplot as plt
plt.plot(pca.explained_variance_ratio_)

Cumulative Variance

Add the ratios up as you go to get cumulative variance, showing the total information kept by the first k components.

import numpy as np
cum = np.cumsum(pca.explained_variance_ratio_)

Pick a Threshold

A common rule is to keep enough components to reach a target, like 95 percent of total variance retained.

Let scikit-learn Choose

Pass a fraction as n_components and scikit-learn keeps just enough components to hit that explained-variance target.

from sklearn.decomposition import PCA
pca = PCA(n_components=0.95).fit(X)

The Kaiser Rule

Another guide, the Kaiser rule, keeps components whose eigenvalue exceeds one, meaning they explain more than a single feature would.

Balance the Trade-Off

Fewer components mean simpler, faster models but more lost detail. Choosing k is always a trade-off between size and fidelity.

Validate Downstream

The best k is the one that helps your real task. Try a few values and compare model scores with cross-validation.

Beware Tiny Components

Components past the elbow often capture mostly noise. Keeping them rarely helps and can quietly hurt your model.

Quick Check

The scree plot points you to one telltale spot.

Recap

Use a scree plot, elbow, or a cumulative-variance threshold to keep just enough components, then validate k downstream. 🎯

Frequently asked questions

Is the “Choose Components With Scree Plots” lesson free?

Yes — the full text of “Choose Components With Scree Plots” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Choose Components With Scree Plots”?

Keeping enough explained variance. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Choose Components With Scree Plots” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Curse of Too Many Features
  2. How PCA Finds Components
  3. Scale First, Then Fit PCA
  4. Choose Components With Scree Plots
← Back to Data Science Academy