Straight or Curved?

Machine Learning in CodeMedium+10 XP+10

Straight or Curved?

A clinic can only afford some of the ten diabetes measurements. For a given set of columns, they want to know whether a curved model earns its extra columns.

Write straight_or_curved(columns).

  • Load the data with load_diabetes(return_X_y=True, as_frame=True) and split it with train_test_split(X, y, test_size=0.25, random_state=0).
  • Keep only the columns named in columns.
  • Straight: make_pipeline(StandardScaler(), LinearRegression()).
  • Curved: make_pipeline(PolynomialFeatures(2), StandardScaler(), LinearRegression()).
  • Fit both on the training rows and score both on the test rows (R²).

Return a dict:

  • "straight": the straight model's test R², rounded to 3 places.
  • "curved": the curved model's test R², rounded to 3 places.
  • "ship": "curved" if the curved model's unrounded test R² is higher, otherwise "straight".

Examples

columns = ['s3']
returns {'straight': 0.064, 'curved': 0.076, 'ship': 'curved'}
columns = ['bmi', 's5']
returns {'straight': 0.276, 'curved': 0.261, 'ship': 'straight'}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run