Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Regression lessonsQUESTIONS · MODELS · EVIDENCE
Curves and trees · ML-R-R2 · 15–20 MIN

Flexibility 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 · MIX60_REVIEW

Retrieve without the worked example: Expand distance and weight to degree two; report feature names.

Use the new retrieval population shown here.

Retrieve earlier concepts before combining them.

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

Given data · MIX60_REVIEW

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

MIX60_REVIEW · first 8 prepared rows
distanceweightserviceweekendduration
15.41066.72438standard059.8192
9.548344.7947express136.569
17.21055.70745economy059.5671
14.32977.80743standard156.8985
2.880026.18273express019.4598
19.01235.64716economy176.7485
15.59675.59089standard057.2908
15.67493.15065express153.9559

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
distancefloat64
weightfloat64
servicestr
weekendint64
durationfloat64

Supporting concepts: Validate polynomial flexibility → · Control tree complexity →

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 that two-input expansion creates interactions as well as powers.

Hint 2 — Tools

PolynomialFeatures and fitted feature names.

Hint 3 — Approach

Fit the requested expansion to the declared schema and inspect its generated names.

Explained solution
from sklearn.preprocessing import PolynomialFeatures
expander=PolynomialFeatures(degree=2,include_bias=False).fit(df[['distance','weight']])
answer=list(expander.get_feature_names_out())

The named representation makes all degree-two terms visible without assuming expansion means only squaring each column.

Helpful prior knowledge: Validate polynomial flexibility · Control tree complexity 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: Expand distance and weight to degree two; report feature names. 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.