Open xuzhang5788 opened 3 years ago
Hey, @xuzhang5788 , have you considered creating a wrapper class like this one?
class PrefitEstimator(sklearn.base.BaseEstimator):
def __init__(self, prefit_estimator):
self.prefit_estimator = prefit_estimator
def __getattr__(self, attr):
'''
gets the attributes from prefit_estimator, except if the attribute (or method)
is "fit".
if the "transform" or "predict" method is called, it'll return self.prefit_estimator's method
'''
if attr == 'fit':
return self.fit
elif attr == 'fit_transform':
return self.fit_transform
elif attr == 'fit_predict':
return self.fit_predict
else:
return getattr(self.prefit_estimator, attr)
def fit(self, X, y = None, **kwargs):
'''
the fit method does nothing (since prefit_estimator is already fitted) and returns self.
'''
return self
def fit_transform(self, X, y = None, **kwargs):
return self.transform(X) #will get "transform" method from self.prefit_estimator
def fit_predict(self, X, y = None, **kwargs):
return self.predict(X) #will get "predict" method from self.prefit_estimator
Excellent question @xuzhang5788. Did @AlanGanem 's solution work?
@tanweer-mahdi I didn't try. If you would like to try, please let me know if it works. Many thanks.
I already have trained several models, I want to ensemble them in the end. I don't want to retrain my models. I can get model.predict(test) values. How to stack them together using mlens? Many thanks