I keep failing with custom transformer implementation. I posted a question on 
stackoverflow, and deleted it as I think it should be more appropriate here.
I followed the suggestions by other people. The code right now is this:

    from sklearn.base import TransformerMixin, BaseEstimator

    class myRegressor(BaseEstimator, TransformerMixin):
        def __init__(self, list1=None, list2=None):
            self.list1_ = list1
            self.list2_ = list2
            self.var_ = # something
            print self.list1_
            print self.list2_
            print list1
            print list2
        def fit(self, X, y):
            # some code
            return self
        def transform(self, X):
            return something

I then feed the estimator into sklearn pipeline for gridsearch with CV.


1)      Except for the first iteration of grid search, all other times the 
lists I print from within __init__() function are None. Same thing from within 
fit().
And I get the same output if I remove `None` from default argument values.

2)      If I do provide get_params (I don't event know if I need to provide it 
with a transformer) I get "__init__: got unexpected keworkd argument " 
etcetera. I'm guessing the issue is the underscore at the end of the parameter 
name. For example :


      def get_params(self, deep=True):
          # suppose this estimator has parameters "alpha" and "recursive"
          return {"list1_": self.list1_, "list2_": self.list2_}

However, if I remove the underscore from the string names, I get
          'GridSearchCV' object has no attribute 'best_estimator_'



Thanks,


------------------------------------------------------------------------------
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