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".unknownnever 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:
keptand thereasonsfor dropping.- feature_names_in_, n_features_in_
As in scikit-learn.
- Parameters:
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
Xand 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,
keepcolumns absent fromX, or when every column would be dropped.
- Parameters:
- Return type:
- fit_transform(X, y=None, **fit_params)[source]#
Fit to data, then transform it.
Fits transformer to
Xandywith optional parametersfit_paramsand returns a transformed version ofX.- 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
fitmethod.
- 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:
- get_metadata_routing()[source]#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating 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
transformandfit_transform."default": Default output format of a transformer"pandas": DataFrame output"polars": Polars outputNone: 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.