Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← PCA lessons
Reading a representation · ML-P07 · 18–25 MIN

Equivalent signs and reconstruction

Understand equivalent representations and information loss.

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

Understand the idea

Paired sign flips preserve the representation. Reconstructing from fewer axes omits variation; low reconstruction error is still not a causal interpretation.

Understand equivalent representations and information loss.score × axis weights(−score) × (−weights)=Consistent sign reversal preserves the reconstruction.Discarding components, unlike reversing signs, loses information.
Understand equivalent representations and information loss.Scroll the diagram horizontally if needed.

What the syntax does

pca.inverse_transform(scores)
  • Maps component coordinates back into the scaled feature space; a truncated representation loses information.

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.
PCA48 · first 8 rows
abcde
103.04750.862222.715744.61840.906993
89.600244.301520.270340.1253-0.680116
107.50553.952121.156541.70090.818161
109.40654.250122.525244.90951.39291
80.489640.055714.171429.4087-3.27953
86.978244.138718.721337.5997-1.70077
101.27850.461118.118536.0784-0.343557
96.837648.787517.444533.8533-0.987809
Your task
  1. Flip the first component’s weights.
answer
Hints

Think: Changing an axis direction changes weight signs without changing its variance.

Tools: Component indexing and multiplication by minus one.

Approach: Select the first fitted axis and reverse every weight consistently.

Explained solution
answer=pca.components_[0]*-1

The output represents the same one-dimensional direction with its orientation reversed.

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.