Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Classification lessons
Margins and rules · ML-C12 · 25–40 MIN

One feature, one rule

Understand the production One-R rule and fallback.

  1. FollowRead and run the PythonCurrent exercise
  2. ChangeAdapt the Python
  3. TransferCompute and inspect the evidence
  4. ApplyBuild a guided full workflow

Understand the idea

One-R evaluates single-feature rules and chooses one with the fewest training errors. Production preserves discrete feature metadata and uses a majority fallback for unknown rule values.

Understand the production One-R rule and fallback.One selected feature → majority rule for each valueServiceRule predictionstandardon timeexpresson timeeconomylateSelect by training errors; unseen values use a fallback.
Understand the production One-R rule and fallback.Scroll the diagram horizontally if needed.

What the syntax does

model.named_steps['model']
  • The model step is the fitted One-R classifier.
  • Its rules_ dictionary stores the learned rules; the preparation step has already supplied the feature representation.
  • Reading rules does not fit again.
  • The prepare step contains fitted preparation; model contains the prediction estimator.
  • A ColumnTransformer also exposes its named_transformers_ when inspecting encoded categories.

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[['service', 'fragile']]
y
Target series, aligned with X.
y = df.label
model
Already fitted on X, y. Fitted estimator or pipeline for the requested model family. Fitted on X, y; reuse without refitting.

Outputs you create

answer
  1. The requested result, with the values, labels and row order described by this task.
RULE24 · first 8 rows
distanceservicefragilelabel
1standard0on time
2express1on time
3economy0late
4standard1on time
5express0on time
6economy1on time
7standard0on time
8express1on time
Your task
  1. Store the fitted One-R classifier’s rules_ dictionary in answer.
answer
Hints

Think: One-R retains a single selected feature’s mapping rather than combining all inputs.

Tools: The fitted One-R step and rules_.

Approach: Access the classifier inside the pipeline and inspect its learned rules.

Explained solution
answer=model.named_steps['model'].rules_

The rule mapping makes the simple classifier inspectable and keeps its limited expressiveness visible.

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.