FeatureRenamer#
- class scikitplot.feature_selection.FeatureRenamer(rule=None, *, start=0, on_collision='raise', on_missing='raise')[source]#
Rename columns with a plan frozen at fit time.
- Parameters:
- rulemapping, sequence of str, callable, str or None, default=None
Naming rule (see
RenamePlan):{"old": "new"}, a list of new names,callable(name), or a template such as"f{index}". None keeps every name.- startint, default=0
First
{index}of a template.- on_collision{“raise”, “suffix”}, default=”raise”
Handling of duplicate new names.
- on_missing{“raise”, “ignore”}, default=”raise”
Handling of mapping keys that are not columns.
- Attributes:
- plan_RenamePlan
The frozen plan.
- feature_names_in_ndarray of str
Set only when fitted on a DataFrame, as in scikit-learn.
- n_features_in_int
Input count. A NumPy input is named
x0, x1, ...for the rule.
- Parameters:
Notes
User note. Output is always a DataFrame. A callable rule runs once in
fit;transformonly applies the stored plan, so test data can never be renamed differently. Define callables withdef(notlambda) if the pipeline must be pickled.Examples
>>> import pandas as pd >>> from scikitplot.feature_selection import FeatureRenamer >>> X = pd.DataFrame({"num__age": [1, 2], "cat__city_a": [0, 1]}) >>> FeatureRenamer(lambda n: n.split("__", 1)[1]).fit_transform(X).columns.tolist() ['age', 'city_a']
- fit(X, y=None)[source]#
Build and freeze the rename plan from the columns of
X.- Parameters:
- Xpandas.DataFrame or array-like
Training data.
- yignored
Present for API consistency.
- Returns:
- selfFeatureRenamer
The fitted renamer.
- 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 one-to-one lineage of this step.
- Parameters:
- input_featuresarray-like of str or None, default=None
Checked as in
get_feature_names_out.
- Returns:
- FeatureMapping
The identity 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.