Apply a Fit/Transform Pipeline
Apply a Fit/Transform Pipeline
A pipeline is an ordered list of transformation steps. Each step exposes two operations:
fit(X) → learns parameters from X and stores them internallytransform(X) → applies the learned transformation to XThe correct pattern:
1. On training data: call fit_transform(X_train) for each step, passing the result to the next step
2. On test data: call only transform(X_test) for each step — never refit
You are given a pipeline as a list of step objects, each with .fit(X) and .transform(X) methods.
Your task:
Implement:
fit_pipeline(steps, X_train) — fits all steps sequentially, returning the final transformed training datatransform_pipeline(steps, X_test) — transforms test data through already-fitted stepsExample Tests
Single mean-centering step: training output has zero mean
Input: {"X_test":[[3]],"X_train":[[1],[3],[5]],"pipeline_spec":"mean_center_1step"}
Expected: [[0]]
Two steps applied in order: test output uses train statistics only
Input: {"X_test":[[2]],"X_train":[[0],[4]],"pipeline_spec":"mean_center_then_scale_2step"}
Expected: [[0]]
Empty pipeline returns input unchanged
Input: {"X_test":[[5]],"X_train":[[1],[2]],"pipeline_spec":"empty"}
Expected: [[5]]