Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support transforming Transformers into stateful transforms #14

Open
jnothman opened this issue Mar 1, 2018 · 2 comments
Open

Support transforming Transformers into stateful transforms #14

jnothman opened this issue Mar 1, 2018 · 2 comments

Comments

@jnothman
Copy link

jnothman commented Mar 1, 2018

basically we need some kind of mixin or wrapper that does:

class transformer_to_patsy:
    def __init__(self, transformer, use_partial_fit=False):
        self.fitted = False
        self.use_partial_fit = use_partial_fit
        self.transformer = transformer

    def memorize_chunk(self, X):
        if self.use_partial_fit:
            self.transformer.partial_fit(X)
        elif self.fitted:
            raise RuntimeError
        else:
            self.fitted = True
            self.transformer.fit(X)

    def memorize_finish(self):
        pass

    def transform(self, X):
        return self.transformer.transform()

Then you can define quantiletransform = transformer_to_patsy(QuantileTransformer()) and use quantiletransform(mycategories) in a formula.

@jnothman
Copy link
Author

jnothman commented Mar 1, 2018

Function composition would also implicitly yield a pipeline. Of course hyperparameter search over transformers would become pretty impossible, but still this seems worth supporting.

@jnothman
Copy link
Author

jnothman commented Mar 1, 2018

hmm. we'll need some cloning in there at some point too...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant