Yes, itβs possible, but you must fulfill the same requirements that are required for Pipeline to be executed during initialization, that is, you cannot insert a predictor at any step except the last, you must call fit after updating Pipeline.steps, because after such an update all steps (they may have been studied in previous calls to fit ) will be invalid, also the last Pipeline step should always implement the fit method, all previous steps should implement fit_transform .
So, yes, this will work in the current codebase, but I think this is not a good solution for your task, it makes your code more dependent on the current Pipeline implementation, I think it is more convenient to create a new pipeline with modified steps, because Pipeline, at least, will check all your steps during initialization, also creating a new Pipeline will not differ significantly in terms of speed from changing the steps of the existing pipeline, but, as I said, creating a new Pipeline after each modification of the steps is safer when, if someone significantly changes the implementation of the pipeline.
source share