Standard scaler without leakage showed why preprocessing must learn its statistics from training data only. Real projects chain several preprocessing steps, and doing that by hand invites mistakes. A pipeline bundles the steps in order: fitting the pipeline fits each step on the output of the previous one, and transforming new data replays the same sequence with the fitted numbers.
Implement two classes.
MinMaxScaler: fit(X) stores each column's minimum and maximum. transform(X) returns (X - min) / (max - min). A column whose training range is zero maps every value to 0. fit_transform(X) fits, then transforms X, and returns the result.Pipeline(steps): steps is a list of transformers. fit_transform(X) runs each step's fit_transform in order and returns the final output. transform(X) runs each step's transform in order.transform never refits anything. Values outside the training range may fall outside [0, 1], and that is correct.fit returns the scaler itself, so calls can be chained.Open one at a time. Each gives away a little more than the last.
For a zero range, divide by np.inf instead of zero: finite values divided by infinity become zero, with no warnings.
In Pipeline.fit_transform, reassign X at each step: X = step.fit_transform(X).
No results yet
Run your code to check it against the examples, or submit to run every test.