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
ColumnTransformerdriven by a feature schema.Called with the training frame when the
ColumnTransformeris fitted, it profiles that frame (or uses a fixedschema) and returns the matching column names;ColumnTransformerstores 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_selectorThe dtype-based counterpart.
Notes
User note. With
schema=Nonethe 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 passschema=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'])]
- schema: FeatureSchema | None = None#