Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← PCA lessons
Reading a representation · ML-P06 · 12–18 MIN

Two dimensions are a view

Separate a display from the retained representation.

  1. FollowRead and run the PythonCurrent exercise
  2. ChangeAdapt the Python
  3. TransferCompute and inspect the evidence

Understand the idea

A two-component picture may show much less variation than the full reduced representation. Label the variance visible in it. Optional reference colouring belongs after fitting and does not prove classes are recovered.

Separate a display from the retained representation.Retained scores: rows × kDisplay: first two scoresThe display omits axes after PC2 when k > 2.Report their variance; keep the retained representation.
Separate a display from the retained representation.Scroll the diagram horizontally if needed.

Supplied for this practice

These objects are prepared afresh before your editor runs.

X
Feature dataframe for the declared population, preserving row indices.
X = df.copy()
scaler
Already fitted coordinate system learned from X; transform reuses its statistics without fitting again. Fitted on X; reuse without refitting.
scaled
Standardised features in the same row/column order as X.
scaled = scaler.fit_transform(X)
pca
Already fitted on scaled. PCA fitted on scaled measurements. Fitted on scaled; reuse without refitting.
scores
Supplied scores; its definition below specifies the values and role.
scores = pca.transform(scaled)

Outputs you create

answer
  1. The requested result, with the values, labels and row order described by this task.
PCA60_MIXED · first 8 rows
abcde
84.607341.797123.268544.0585-1.48542
118.32758.820124.000745.4287-0.0617574
95.996543.354823.841638.02320.0332781
96.427649.114223.051146.07730.139073
113.80962.443522.657353.2181-0.764884
111.1253.135714.811828.17741.18599
107.79656.096118.592541.5523-0.874061
105.98852.410216.652434.00580.290617
Your task
  1. Report the variation visible in the first two axes.
answer
Hints

Think: The visible two-dimensional view may retain less variation than the full chosen representation.

Tools: Summing the first two explained-variance ratios.

Approach: Add the ratios for the plotted axes and report the resulting fraction.

Explained solution
answer=float(pca.explained_variance_ratio_[:2].sum())

The fraction states how much fitted input variation the picture can show and qualifies what it omits.

Ctrl/⌘+Enter: Run · Tab: indent · Esc then Tab: leave editor

Python loads when you run. Code and results stay in this activity only.

Run your code to inspect its output. Check uses that same run.