Skip to main content

A Package to use pandas DataFrame in sklearn pipeline. And others useful works to use sklearn pipeline in non usual way.

Project description

The main use of this package is to use Sklearn Pipeline with transformer / estimator that doesn't comply with the basic Pipeline:

1 - Use sklearn Pipeline with transformation on Y:

from sklearn_pandas_transformers.transformers import SplitXY, EstimatorWithoutYWrapper, SklearnPandasWrapper

from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import StandardScaler
from sklearn.impute import KNNImputer
from sklearn.pipeline import Pipeline
import pandas as pd
import numpy as np

input_df = pd.DataFrame([[0, 1, 2, 3], [4, 5, 6, 7], [8, np.nan, 9, 10]])
input_df.columns = ["a", "b", "c", "d"]

spliter = SplitXY("a")

pipe = Pipeline([
        ("imputer", SklearnPandasWrapper(KNNImputer())),
        ("spliter", spliter), ("scaler", StandardScaler()),
        ("rf",
            EstimatorWithoutYWrapper(RandomForestRegressor(random_state=45),
                                    spliter))
    ])
pipe.fit(input_df)

res = pipe.predict(input_df)

2 - Use sklearn Transformer (returning numpy array) to return pandas DataFrame (with unchanged columns names):

SklearnPandasWrapper(StandardScaler()))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sklearn-pandas-transformers-0.0.12.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page