Hi Vlad/All,
Thanks for the pointers. The reason I return a copy of X is because I don't
want to modify the dataset during grid search with cross validation (I'm not
sure if the argument of transform is a deep copy or shallow copy).
I implemented the class like the below. Basically a transformer that does
nothing, with no parameters.
class myTransformer(BaseEstimator, TransformerMixin):
def __init__(self):
pass
def fit(self, *args, **kwargs):
return self
def transform(self, X, **transform_params):
return X.copy()
def set_params(self, **params):
return self
def get_params(self, deep=True):
return None
I'm getting this error when using it in a pipeline (during grid search cv,
where the pipeline is standard scaler + myTransformer + svm ):
'NoneType' object has no attribute 'iteritems'
Do you know what the issue might be?
Thank you,
-----Original Message-----
From: Vlad Niculae [mailto:[email protected]]
Sent: Monday, February 16, 2015 1:04 PM
To: [email protected]
Subject: Re: [Scikit-learn-general] which methods do I need to implement for a
regressor?
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 <[email protected]> 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
> [email protected]
> 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
[email protected]
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general