KeepPandas
Wrapper to keep column names of pandas dataframes in a scikit-learn
transformer.
Any scikit-learn transformer wrapped in KeepPandas will return a pd.DataFrame
on .transform()
.
Warning
You should only use KeepPandas()
when you know for sure scikit-learn
did not change the order of your columns.
Examples:
from skorecard.pipeline import KeepPandas
from skorecard import datasets
from skorecard.bucketers import EqualWidthBucketer
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X, y = datasets.load_uci_credit_card(return_X_y=True)
bucket_pipeline = make_pipeline(
KeepPandas(StandardScaler()),
EqualWidthBucketer(n_bins=5, variables=['LIMIT_BAL', 'BILL_AMT1']),
)
bucket_pipeline.fit_transform(X, y)
__init__(self, transformer)
special
¶
Initialize.
__repr__(self)
special
¶
String representation.
fit(self, X, y=None, *args, **kwargs)
¶
Fit estimator.
fit_transform(self, X, y=None, **fit_params)
inherited
¶
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit_params
and returns a transformed version of X
.
Parameters¶
X : array-like of shape (n_samples, n_features) Input samples.
y : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None Target values (None for unsupervised transformations).
**fit_params : dict Additional fit parameters.
Returns¶
X_new : ndarray array of shape (n_samples, n_features_new) Transformed array.
get_feature_names(self)
¶
Return estimator feature names.
get_params(self, deep=True)
inherited
¶
set_params(self, **params)
inherited
¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as :class:~sklearn.pipeline.Pipeline
). The latter have
parameters of the form <component>__<parameter>
so that it's
possible to update each component of a nested object.
Parameters¶
**params : dict Estimator parameters.
Returns¶
self : estimator instance Estimator instance.
transform(self, X, *args, **kwargs)
¶
Transform X.