FeatureFilter#

class scikitplot.feature_selection.FeatureFilter(policy=None, *, drop=('constant', 'identifier_like'), keep_roles=('feature',), keep=(), on_mismatch='raise')[source]#

Drop features whose assessments are true, and columns with non-feature roles.

Parameters:
policyFeaturePolicy, mapping, path or None, default=None

Profiling policy.

dropsequence of str, default=(“constant”, “identifier_like”)

A feature is dropped when any of these assessments is "true". unknown never drops.

keep_rolessequence of str, default=(“feature”,)

Roles that survive; every other role (target, identifier, drop …) is removed so it cannot leak into the model.

keepsequence of str, default=()

Columns kept regardless of their assessments (not of their role).

on_mismatch{“raise”, “warn”, “ignore”}, default=”raise”

As in FeatureProfiler.

Attributes:
schema_FeatureSchema

Fitted schema.

support_ndarray of bool

Kept columns.

report_pandas.DataFrame

One row per column: kept and the reasons for dropping.

feature_names_in_, n_features_in_

As in scikit-learn.

Parameters:
  • policy (Any)

  • drop (Sequence[str])

  • keep_roles (Sequence[str])

  • keep (Sequence[str])

  • on_mismatch (str)

Examples

>>> import pandas as pd
>>> from scikitplot.feature_selection import FeatureFilter
>>> X = pd.DataFrame(
...     {"id": [f"r{i}" for i in range(30)], "c": [1] * 30, "x": list(range(30))}
... )
>>> f = FeatureFilter().fit(X)
>>> f.get_feature_names_out().tolist()
['x']
>>> f.report_.loc["id", "reasons"]
('identifier_like',)
fit(X, y=None)[source]#

Profile X and decide which columns to keep.

Parameters:
Xpandas.DataFrame

Training data.

yignored

Present for API consistency.

Returns:
selfFeatureFilter

The fitted filter.

Raises:
ValueError

For unknown assessment or role names, keep columns absent from X, or when every column would be dropped.

Parameters:
Return type:

FeatureFilter

fit_transform(X, y=None, **fit_params)[source]#

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:
Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_feature_lineage(input_features=None)[source]#

Return the exact subset lineage of this step.

Parameters:
input_featuresarray-like of str or None, default=None

Must equal feature_names_in_ when given.

Returns:
FeatureMapping

The mapping.

Parameters:

input_features (Any)

Return type:

FeatureMapping

get_feature_names_out(input_features=None)[source]#

Return the kept column names.

Parameters:
input_featuresarray-like of str or None, default=None

Must equal feature_names_in_ when given.

Returns:
ndarray of str

Kept names.

Parameters:

input_features (Any)

Return type:

ndarray

get_metadata_routing()[source]#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)[source]#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

get_support(indices=False)[source]#

Return the mask (or indices) of kept input columns.

Parameters:
indicesbool, default=False

Return integer positions instead of a mask.

Returns:
ndarray

Boolean mask or integer positions.

Parameters:

indices (bool)

Return type:

ndarray

set_output(*, transform=None)[source]#

Set output container.

Refer to the user guide for more details and Introducing the set_output API for an example on how to use the API.

Parameters:
transform{“default”, “pandas”, “polars”}, default=None

Configure output of transform and fit_transform.

  • "default": Default output format of a transformer

  • "pandas": DataFrame output

  • "polars": Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: "polars" option was added.

Returns:
selfestimator instance

Estimator instance.

set_params(**params)[source]#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

transform(X)[source]#

Return the kept columns of X.

Parameters:
Xpandas.DataFrame

Data with the fitted columns.

Returns:
pandas.DataFrame

Kept columns in fitted order.

Parameters:

X (DataFrame)

Return type:

DataFrame