Question 6
The following code attempts to implement Ridge regression on the Boston housing dataset but contains an error. The missing part should be correctly filled in to avoid issues during training.
import numpy as npimport pandas as pdfrom sklearn.datasets import load_bostonfrom sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import StandardScalerfrom sklearn.linear_model import Ridgefrom sklearn.pipeline import Pipeline
# Load datasetdata = load_boston()X, y = data.data, data.target
# Split into training and test setsX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Define the Ridge regression model with standardizationmodel = Pipeline([ ('scaler', StandardScaler()), ('ridge', Ridge(alpha=1.0))])
# Missing part
# Make predictionsy_pred = model.predict(X_test)Which of the following correctly fills the missing part while ensuring proper preprocessing?