python - Does GridSearchCV call initialisers of the objects in pipeline? -


i wrote code process kaggle's titanic data. class wrote follows:

class transform(baseestimator,transformermixin):       def __init__(self,select_dict={},default=false,list_of_attributes=dataset_columns,              one_hot_default=true,one_hot={}):        if list_of_attributes none:             list_of_attributes=dataset_columns        self.attributes=select_dict #here select attributes take        self.transformed=[]        #if default false(true) changes other attributes        #default not select (to make things little easy    def transform_name(self,x):        #transformation function specific attribute        #i made such functions every attribute , append        #the transformed series in self.transformed        self.transformed.append(x);      def transform(self,x,y=none):        #this function calls transform function of value true in         #self.attributes , returns dataframe        return pd.concat(self.transformed_data,axis=1) 

i have show relevant code of class.
now, create pipeline using svc class of sklearn

transfomer=transform(select_dict={'passengerid': false},default=true) svc_grid_clf=pipeline([ ('transform',transformer), ('svc',svc()) ])   

once create pipeline create gridsearchcv using following parameter grid

param=[ { 'svc__kernel': ['rbf'], 'svc__c': [0.1,1,1.5] }]   

now creating gridsearchcv object

grid_svm=gridsearchcv(estimator=svc_grid_clf,cv=3,param_grid=param) #now fitting grid_svm.fit(x,y)    

however, receive error not able understand i.e.

valueerror: no objects concatenate.

i believe error because gridsearchcv either calling or not calling init function of transformer, select_dict of transformer not coming should be.

sklearn api requires pass estimator instances everywhere, not estimatoe classes. when create sklearn-compatible estimator, create object holds parameters (but not data). actual work should performed in fit/transform/... methods.

it seems transformer class doesn't follow these api ideas. shouldn't store passed data attributes of class; transformer.transform method should work on passed x matrix, not on self.transformed_data attribute. there example on how write such transformers.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -