FeatureProfiler#

class scikitplot.feature_selection.FeatureProfiler(policy=None, *, output='all', on_mismatch='raise')[source]#

Fit a feature schema on the training data; pass data through unchanged.

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

Profiling policy (see FeaturePolicy).

output{“all”, “features”}, default=”all”

"all" returns every fitted column; "features" only the columns whose role is "feature" (target, identifier, drop … removed).

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

What transform does with extra, reordered or retyped columns. Missing columns always raise. Output always has the fitted columns in the fitted order.

Attributes:
schema_FeatureSchema

Schema fitted on the training data.

feature_names_in_ndarray of str

Columns seen in fit.

n_features_in_int

Their count.

Parameters:
  • policy (Any)

  • output (str)

  • on_mismatch (str)

See also

profile_features

The same without scikit-learn.

FeatureFilter

Drops features by assessment.

Notes

User note. Put it first in a pipeline to keep the training schema next to the model: pipe.named_steps["profile"].schema_. Use audit on validation or test data to see structural differences without refitting.

Examples

>>> import pandas as pd
>>> from scikitplot.feature_selection import FeatureProfiler
>>> X = pd.DataFrame({"a": [1.0, 2.0, 3.0] * 4, "id": [str(i) for i in range(12)]})
>>> prof = FeatureProfiler(
...     policy={"roles": {"identifier": ["id"]}}, output="features"
... )
>>> prof.fit_transform(X).columns.tolist()
['a']
>>> prof.schema_["id"].role
'identifier'
audit(X)[source]#

Return FeatureSchema.audit of X.

Parameters:
Xpandas.DataFrame

Later data.

Returns:
pandas.DataFrame

Structural findings.

Parameters:

X (DataFrame)

Return type:

DataFrame

fit(X, y=None)[source]#

Fit the schema on X.

Parameters:
Xpandas.DataFrame

Training data.

yignored

Present for API consistency.

Returns:
selfFeatureProfiler

The fitted profiler.

Parameters:
Return type:

FeatureProfiler

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 lineage of this step (a subset or the identity).

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 output column names.

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

Must equal feature_names_in_ when given.

Returns:
ndarray of str

Output 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.

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]#

Check X against the schema and return the fitted columns.

Parameters:
Xpandas.DataFrame

Data to pass through.

Returns:
pandas.DataFrame

X itself when it already has exactly the output columns, otherwise X[output columns].

Raises:
SchemaMismatchError

For missing columns, or other differences with on_mismatch="raise".

Parameters:

X (DataFrame)

Return type:

DataFrame