FeatureColumnSelector#

class scikitplot.feature_selection.FeatureColumnSelector(kind=None, family=None, role='feature', tag=None, is_=(), is_not=(), names=None, policy=None, schema=None)[source]#

Column selector for ColumnTransformer driven by a feature schema.

Called with the training frame when the ColumnTransformer is fitted, it profiles that frame (or uses a fixed schema) and returns the matching column names; ColumnTransformer stores them, so validation and test data are transformed with the training selection.

Parameters:
kind, family, role, tag, is_, is_not, names

Conditions, as in FeatureSchema.select. Sequences are stored as tuples.

policyFeaturePolicy, mapping, path or None, default=None

Policy used to profile each training frame.

schemaFeatureSchema or None, default=None

Use this fitted schema instead of profiling; its selected columns must all be present in the frame.

Parameters:

See also

sklearn.compose.make_column_selector

The dtype-based counterpart.

Notes

User note. With schema=None the selection is learned per training fold, which is the correct behaviour under cross-validation. Each selector profiles the frame it is given; with many selectors on a very wide frame, profile once and pass schema= for speed (accepting that the schema was fitted outside the folds).

Examples

>>> import pandas as pd
>>> from sklearn.compose import ColumnTransformer
>>> from sklearn.preprocessing import OneHotEncoder, RobustScaler, StandardScaler
>>> from scikitplot.feature_selection import FeatureColumnSelector
>>> X = pd.DataFrame(
...     {
...         "income": [1.0, 2.0, 2.5, 3.0, 400.0] * 4,
...         "height": [1.6, 1.7, 1.8, 1.75, 1.65] * 4,
...         "city": list("abcab") * 4,
...     }
... )
>>> ct = ColumnTransformer(
...     [
...         (
...             "skewed",
...             RobustScaler(),
...             FeatureColumnSelector(kind="numeric_continuous", is_=("skewed",)),
...         ),
...         (
...             "normal",
...             StandardScaler(),
...             FeatureColumnSelector(
...                 kind="numeric_continuous", is_not=("skewed",)
...             ),
...         ),
...         (
...             "cat",
...             OneHotEncoder(),
...             FeatureColumnSelector(kind="categorical_nominal"),
...         ),
...     ]
... ).fit(X)
>>> [(name, cols) for name, _, cols in ct.transformers_]
[('skewed', ['income']), ('normal', ['height']), ('cat', ['city'])]
__call__(X)[source]#

Return the matching columns of X.

Parameters:
Xpandas.DataFrame

The frame given to ColumnTransformer.fit.

Returns:
list of str

Matching column names in frame order.

Parameters:

X (DataFrame)

Return type:

list[str]

family: Any = None#
is_: Sequence[str] = ()#
is_not: Sequence[str] = ()#
kind: Any = None#
names: Sequence[str] | None = None#
policy: Any = None#
role: Any = 'feature'#
schema: FeatureSchema | None = None#
tag: Any = None#