flennerhag / mlens

ML-Ensemble – high performance ensemble learning
http://ml-ensemble.com
MIT License
843 stars 108 forks source link

DataFrame Support? #117

Closed samyip123 closed 5 years ago

samyip123 commented 5 years ago

I am using estimators that require dataframes as input, using the index values, it seems first layer accepts it, but when using the estimator in higher layers, the data will be sliced into ndarrays before passing into the 'fit' and 'predict_proba' functions of the estimator, is there a way to preserve them as dataframes when passing through? thanks

flennerhag commented 5 years ago

Hi!

Sorry for late reply. Yes, the predictions of intermediate and the final layer are cast into numpy arrays. The simplest way to turn them into dataframes is to create a preprocessing step that takes the numpy . array and outputs a dataframe, that would like something like


class ToDF:

    def __init__(self):
        pass

    def fit(self, *args, **kwargs):
        return self

    def transform(self, x):
        if not isinstance(x, pd.DataFrame):
            x = pd.DataFrame(x)
        return x