Hi Roberto,

This is all documented in more detail here: [1]

The transform looks good (just that you might want to add a flag to avoid 
memory copies when you can afford to destroy the original data).

It’s not clear what the intention of `my_param` is here. It’s not user 
specified, right? Conventionally, fitted attributes are suffixed with an 
underscore (`self.my_param_`) and you shouldn’t initialize them in `__init__` 
(see [2])

Also, if you do intend to have user-specified attributes, this would break grid 
search, because your `set_params` function does nothing. There are 
implementations of `set_params` and `get_params` in 
`sklearn.base.BaseEstimator`, as Gael said. Just inherit from the 
`BaseEstimator` and those should work, as long as you respect the scikit-learn 
convention that the `__init__` function doesn’t change the parameters (see [3])

Hope this helps!

Yours,
Vlad

[1] 
http://scikit-learn.org/stable/developers/index.html#rolling-your-own-estimator
[2] http://scikit-learn.org/stable/developers/index.html#estimated-attributes
[3] http://scikit-learn.org/stable/developers/index.html#parameters-and-init

> On 16 Feb 2015, at 12:52, Pagliari, Roberto <rpagli...@appcomsci.com> wrote:
> 
> I looked into some examples I found online but I’m a bit confused. 
>  
> Supposed I want to implement my own transformer, something similar to the 
> standard scaler. Would this be sufficient to be used in a pipeline, or should 
> it be done differently?
>  
>  
> class ModelTransformer(TransformerMixin):
>  
>     def __init__(self, model):
>         self.my_param = None
>  
>     def fit(self, *args, **kwargs):
>         # do some stuff
>         self.my_param = something
>         return self
>  
>     def transform(self, X, **transform_params):
>         # do something with self.myparam and X.copy()
>         return X.copy()
>  
>     def set_params(**params):
>         return self
>  
>     def get_params(deep=True):
>         return None
>  
> Thank you,
>  
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk_______________________________________________
> Scikit-learn-general mailing list
> Scikit-learn-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to