Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Clustering and Discovery lessons
Hierarchical discovery · ML-U-R2 · 15–20 MIN

Hierarchy retrieval

  1. Retrieval 1Compute and inspect the evidenceCurrent exercise
  2. Retrieval 2Retrieve the method
  3. Retrieval 3Compute and inspect the evidence

Outputs you create

scaled_mm
  1. Requested result described in the task and deliverables.
answer
  1. The requested result, with the values, labels and row order described by this task.
Exercise evidence · ML-U-R2-1 · all 4 rows
length_mmwidth_cm
101
203
302
404
Your task
  1. Standardise each of the two equivalent unit representations using its declared discovery population.
  2. Store them in scaled_mm and answer.
  3. Verify that the prepared geometry agrees.
scaled_mmanswer
Hints

Think: The numeric unit change changes the relative feature contribution to raw distance and can change merges, not just the label. The merge-height magnitudes also use different coordinate scales. Use consistent units and a common scientifically justified representation before comparing algorithms or cuts; standardisation can make this declared unit conversion equivalent.

Tools: Hierarchy retrieval: use the supplied length_mm, width_cm columns and the pandas or model operations introduced in this lesson.

Approach: Compute scaled_mm, answer from the supplied evidence. Preserve the requested labels and row order, then inspect the values before checking.

Explained solution
from sklearn.preprocessing import StandardScaler
scaled_mm = StandardScaler().fit_transform(df)
converted = df.rename(columns={'length_mm':'length_cm'}).copy()
converted['length_cm'] = converted['length_cm'] / 10
answer = StandardScaler().fit_transform(converted)
print(scaled_mm)
print(answer)

The numeric unit change changes the relative feature contribution to raw distance and can change merges, not just the label. The merge-height magnitudes also use different coordinate scales. Use consistent units and a common scientifically justified representation before comparing algorithms or cuts; standardisation can make this declared unit conversion equivalent.

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.