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.
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 onX; reuse without refitting. scaled- Standardised features in the same row/column order as
X.scaled = scaler.fit_transform(X) pca- Already fitted on scaled.
PCAfitted 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- The requested result, with the values, labels and row order described by this task.
a | b | c | d | e |
|---|---|---|---|---|
| 84.6073 | 41.7971 | 23.2685 | 44.0585 | -1.48542 |
| 118.327 | 58.8201 | 24.0007 | 45.4287 | -0.0617574 |
| 95.9965 | 43.3548 | 23.8416 | 38.0232 | 0.0332781 |
| 96.4276 | 49.1142 | 23.0511 | 46.0773 | 0.139073 |
| 113.809 | 62.4435 | 22.6573 | 53.2181 | -0.764884 |
| 111.12 | 53.1357 | 14.8118 | 28.1774 | 1.18599 |
| 107.796 | 56.0961 | 18.5925 | 41.5523 | -0.874061 |
| 105.988 | 52.4102 | 16.6524 | 34.0058 | 0.290617 |
- Report the variation visible in the first two axes.
answerHints
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.