Skip to content

ColumnSelector

Transformer that performs selection of variables from a pandas dataframe.

Useful in pipelines, where we require a step that selects feautures.

Examples:

from skorecard import datasets
from skorecard.preprocessing import ColumnSelector

X, y = datasets.load_uci_credit_card(return_X_y=True)
cs = ColumnSelector(variables=['EDUCATION'])
assert cs.fit_transform(X, y).columns == ['EDUCATION']

__init__(self, variables=[]) special

Transformer constructor.

Parameters:

Name Type Description Default
variables List

list of columns to select. Default value is set to None - in this case, there is no selection of columns.

[]

fit(self, X, y=None)

Fit the transformer.

Here to be compliant with the sklearn API, does not fit anything.

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_params(self, deep=True) inherited

Get parameters for this estimator.

Parameters

deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params : dict Parameter names mapped to their values.

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)

Selects the columns.

Parameters:

Name Type Description Default
X pd.DataFrame

Dataset

required

Last update: 2021-11-24
Back to top