Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Classification lessonsQUESTIONS · MODELS · EVIDENCE
Probabilities and neighbours · ML-C-R1 · 15–20 MIN

Classification evidence retrieval

Retrieval 1

Exercises within this concept

  1. Retrieval 1Retrieve and applyCurrent exercise
  2. Retrieval 2Retrieve and apply
  3. Retrieval 3Retrieve and apply
Retrieval 1 · ERROR12_REVIEW

Retrieve without the worked example: Compute macro F1 for ERROR12.

Use the new retrieval population shown here.

Retrieve earlier concepts before combining them.

This practice: Retrieve earlier concepts before combining them. Next: Retrieval 2 · Classification evidence retrieval.

Given data · ERROR12_REVIEW

12 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.

ERROR12_REVIEW · all rows
actualpredicted
AA
AB
AA
AA
AA
AA
AA
AA
BA
BB
BA
BA

Column meanings and units

Column names describe the supplied features and target. Keep the stated units and row identities when making comparisons.

Synthetic data are deliberately small and reproducible. Their patterns illustrate an idea; they are not evidence about a real population.

Input schema
ColumnStored type
actualstr
predictedstr

Supporting concepts: A logistic workflow →

Remember the idea

Use the inputs and evidence to recover the method. Hints and explained solutions remain collapsed; exact phrasing is not graded.

Retrieve earlier concepts before combining them.Candidate ACandidate BFitValidateCostCompare matching evidence; smaller error can cost more.
Schematic · Retrieve earlier concepts before combining them.Scroll the diagram horizontally if needed.
Hint 1 — Think

Recall how macro averaging handles class imbalance.

Hint 2 — Tools

f1_score and its averaging rule.

Hint 3 — Approach

Score the new actual/predicted labels using the equal-class summary.

Explained solution
from sklearn.metrics import f1_score
answer=f1_score(df.actual,df.predicted,average='macro')

The result summarises per-class F1 equally, so a large class cannot dominate simply through its row count.

Helpful prior knowledge: A logistic workflow These links are guidance, not locks.

Sources and API context

Examples run with this Playground’s scikit-learn 1.4.2 / Pyodide 0.26.4 runtime.

Your task · Retrieval 1

Retrieve without the worked example: Compute macro F1 for ERROR12. Use the new retrieval population shown here.

answer

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.