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.
Python skill: Preserves declared categorical values and learns bins only for declared numeric inputs.
Meet the syntax
OneRPreprocessor(...)
OneRClassifier(bins=5)
model.named_steps["model"].rules_OneRPreprocessor- Preserves declared categorical values and learns bins only for declared numeric inputs.
OneRClassifier(bins=5)- Creates the production one-feature rule learner; bins matters when numeric inputs need discretisation.
model.named_steps["model"].rules_- Reads the learned value-to-label mapping for the selected One-R feature.
Follow the code
Use the numbered comments to connect each Python block to the workflow above.
answer=model.named_steps['model'].rules_
This practice: Read and run the Python. Next: Change · One feature, one rule.
One-R classification · from idea to workflow
Question: How well can one input alone assign a class?
Mechanism: Learn one feature’s category or interval rule and choose it using training evidence.
Watch for: Interactions are ignored; rare categories or unstable cut points can mislead.
Interpret or debug · self-review: Inspect which feature won. Explain why a rule learned before the split leaks information even if the final classifier uses only one feature.
Independent full workflow: ML-X09 · ML-X10. First practise complete regression and classification in F11–F12; check readiness in W-K2–W-K3.
Given data · RULE24
24 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.
| 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 |
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.
| Column | Stored type |
|---|---|
| distance | int64 |
| service | str |
| fragile | int64 |
| label | str |
Supplied setup · available if you need to inspect it
This code runs before your editor on every Run. These are the objects your exercise uses.
from ml_helpers import OneRClassifier,OneRPreprocessor
from sklearn.pipeline import Pipeline
X=df[['service','fragile']]
y=df.label
model=Pipeline([('prepare',OneRPreprocessor(numeric_features=[],categorical_features=['service','fragile'])),('model',OneRClassifier())]).fit(X,y)
Your task · Follow
Store the fitted One-R classifier’s rules_ dictionary in answer.
Hint 1 — Think
One-R retains a single selected feature’s mapping rather than combining all inputs.
Hint 2 — Tools
The fitted One-R step and rules_.
Hint 3 — 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.
Helpful prior knowledge: Macro F1 and imbalance · Keep preparation with the estimator 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.