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
transformdoes 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:
See also
profile_featuresThe same without scikit-learn.
FeatureFilterDrops 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_. Useauditon 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.auditofX.
- 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:
- 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 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:
- 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.
- transform(X)[source]#
Check
Xagainst the schema and return the fitted columns.- Parameters:
- Xpandas.DataFrame
Data to pass through.
- Returns:
- pandas.DataFrame
Xitself when it already has exactly the output columns, otherwiseX[output columns].
- Raises:
- SchemaMismatchError
For missing columns, or other differences with
on_mismatch="raise".
- Parameters:
X (DataFrame)
- Return type: