Fewer Measurements, Lower Score?

Machine Learning in CodeMedium+10 XP+10

Fewer Measurements, Lower Score?

Some blood tests are expensive. A clinic wants to know how well a model does if it only uses a few of the ten measurements.

Write test_score_with(columns).

  • Load the data with load_diabetes(return_X_y=True, as_frame=True).
  • Split it with train_test_split(X, y, test_size=0.25, random_state=0).
  • Keep only the columns named in columns, in both the training and test rows.
  • Fit a LinearRegression model on the training rows.
  • Return its R² score on the test rows, rounded to 3 decimal places.

Examples

columns = ['bmi']
returns 0.158
columns = ['bmi', 's5']
returns 0.276

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