Standardize-then-Ridge Pipeline

Xem dạng PDF

Gửi bài giải

Điểm: 100,00
Giới hạn thời gian: 2.0s
Giới hạn bộ nhớ: 256M

Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python

Task

Implement a two-step pipeline: first standardize the features by subtracting the training mean and dividing by the training standard deviation (set std to 1 where it is 0), then fit ridge regression on the standardized training data using the closed-form solution w = (Xs^T Xs + λI)^{-1} Xs^T y. Apply the same standardization to the test set and predict ytest = Xtests * w. This mimics scikit-learn's Pipeline([StandardScaler, Ridge]).

Input

  • Line 1: n_train d lam — number of training samples, number of features, regularization strength λ
  • Lines 2 to n_train+1: x_1 ... x_d y — training feature values followed by the target
  • Line n_train+2: n_test — number of test samples
  • Lines ntrain+3 to ntrain+n_test+2: x_1 ... x_d — test feature values

Output

Print the predicted values for the test samples space-separated on one line, with up to 10 significant digits each.

Example

Input:

5 2 1.0
1 2 5
2 3 8
3 4 11
4 5 14
5 6 17
3
2 3
4 5
1 1

Output:

-2.727272727 2.727272727 -6.818181818

Scaffolding

Submit a Python file defining:

def sklearn_pipeline(X_train: list[list[float]], y_train: list[float],
                     X_test: list[list[float]], lam: float) -> list[float]:
    ...

Receives training features and targets, test features, and a regularization strength; returns the predicted values for the test set after applying feature standardization and ridge regression.


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.