1
$\begingroup$

Sklearn pipeline I am using has multiple transformers but one of the initial transformers returns numerical type and the consecutive one takes object type variables.

Basically I need squeeze in a:

data[col] = data[col].astype(object)

for the required columns within the pipeline.

Is there any way to do it?

Note: I am using Feature-engine transformers.

$\endgroup$
0
$\begingroup$

You sure can.

One solution off the bat is to extend your estimator that takes object type variables. So what does that mean.

Library that you said are all estimators in the sklearn form fit, predict methodology. So all you have to do is something as follows:

> class modifiedTraf(oldTraf):
>        def __init__(self):
>           super(modifiedTraf, self).__init__():
> 
> bla bla   
> 
>       def fit(self, X):
>           X[col] = X[col].astype(object)
>           super(modifiedTraf,self).fit(X)
>           return self
>       def transform(self, X):
>           X[col] = X[col].astype(object)
>           X=super(modifiedTraf,self).transform(X)
>           return X

Learn more about overriding sklearn classes and super argument for example here

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.