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.
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 onX,y; reuse without refitting.
Outputs you create
answer- The requested result, with the values, labels and row order described by this task.
distance | service | fragile | label |
|---|---|---|---|
| 1 | standard | 0 | on time |
| 2 | express | 1 | on time |
| 3 | economy | 0 | late |
| 4 | standard | 1 | on time |
| 5 | express | 0 | on time |
| 6 | economy | 1 | on time |
| 7 | standard | 0 | on time |
| 8 | express | 1 | on time |
- Store the fitted One-R classifier’s rules_ dictionary in
answer.
answerHints
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.