Skip to content Skip to sidebar Skip to footer

How To Use Cross-validation With Custom Estimator In Sklearn?

I have written a custom estimator class with a fit and transform method. I am able to create a model, train and predict using the model. However, while doing cross-validation, I ru

Solution 1:

I would suggest having the preprocessor inside the pipeline itself. Cross_val_score would try to copy the params of the estimator, it would break when the estimator cannot return the params while calling get_params().

I am not sure whether your pipeline parameter is a Sklearn pipeline because the pipeline object is not iterable.

Solution 2:

As suggested in few comments, this error is because self.processor can't be deep-cloned.

So, the workaround for this error is to remove preprocessing step from this class and move it as independent preprocessing step or inside the pipeline itself.

Post a Comment for "How To Use Cross-validation With Custom Estimator In Sklearn?"