Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Classification lessons
Margins and rules · ML-C13 · 12–18 MIN

One-R with numeric inputs

Keep numeric bin learning inside each fit.

  1. FollowRead and run the PythonCurrent exercise
  2. ChangeAdapt the Python
  3. TransferAdapt the Python

Understand the idea

Production uses fold-local quantile bins for continuous values. Binary flags stay discrete. This is the Playground’s implementation, which differs in discretisation details from the original One-R paper.

Keep numeric bin learning inside each fit.Numeric intervalRule predictionx < aClass Aa ≤ x < bClass Bx ≥ bClass ACut points a and b are learned inside each fit.
Keep numeric bin learning inside each fit.Scroll the diagram horizontally if needed.

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[['distance', 'fragile']]
y
Target series, aligned with X.
y = df.label
model
An unfitted recipe is supplied; construction has not learned parameters. Fit it here only when the task requests fitting.
model = Pipeline([('prepare', OneRPreprocessor(numeric_features=['distance'], categorical_features=['fragile'])), ('model', OneRClassifier(bins=5))])

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. Fit the numeric rule and inspect its predictions.
answer
Hints

Think: Numeric One-R learns intervals before it can map new values to labels.

Tools: Pipeline.fit and predict with numeric-rule preparation.

Approach: Fit the supplied recipe on the aligned features and labels, then inspect predictions.

Explained solution
model.fit(X,y)
answer=model.predict(X)

The fit learns the interval/rule structure; these in-sample outputs illustrate behaviour rather than held-away performance.

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.