scikitplot.feature_selection#
scikitplot.feature_selection#
Understand, group, track and monitor the features of wide pandas tables.
Three questions, three tools:
- What is each feature?
profile_features(orFeatureProfilerin a pipeline) fits aFeatureSchemaon training data. EachFeatureSpecknows its role, dtype family, semantic kind, user tags, a bin recommendation, and policy-backed assessments with evidence (“am I skewed / discrete / constant / binary / identifier-like / high-cardinality …?”). Thresholds live in aFeaturePolicy(TOML, YAML or JSON), and custom questions are registered withregister_assessment.- What happened to each feature in a pipeline?
trace_pipelinereads a fittedPipeline/ColumnTransformer/FeatureUnionand returns aFeatureLineage: which steps touched a raw column, which outputs it became, where it was dropped, andFeatureLineage.attributeto sum one-hot (or any exactly traced) importances back to raw columns.- Has it drifted?
ReferenceProfilefreezes training buckets per feature and reports PSI, Jensen-Shannon distance, missingness change and unseen categories for later data.
The scikit-learn pieces (FeatureColumnSelector for
ColumnTransformer, FeatureFilter, FeatureRenamer) fit
on the training fold only, so they are safe under cross-validation.
Examples
>>> import numpy as np, pandas as pd
>>> from scikitplot.feature_selection import profile_features
>>> rng = np.random.default_rng(0)
>>> X = pd.DataFrame(
... {
... "income": rng.lognormal(10, 1, 300),
... "age": rng.integers(18, 80, 300),
... "kids": rng.integers(0, 4, 300),
... "city": rng.choice(["ankara", "izmir", "bursa"], 300),
... "customer_id": [f"c{i}" for i in range(300)],
... }
... )
>>> schema = profile_features(X)
>>> schema.groups(by="kind")["numeric_continuous"]
['income', 'age']
>>> schema["income"].is_("skewed"), schema["kids"].kind
(True, 'numeric_discrete')
>>> schema.select(is_=("identifier_like",))
['customer_id']
Notes
User note. Profile the training split only and keep the schema
(FeatureSchema.save); audit later splits with
FeatureSchema.audit and ReferenceProfile. Recommendations
(recommend_treatments, analysis_plan, bin plans) are advice and
never modify data.
Developer note. The package is pure Python on top of pandas, NumPy,
SciPy and scikit-learn; PyYAML and tomli-w are needed only to read YAML or
write TOML. Every persisted artefact carries a schema_version and is
checked field by field on load.
User guide. See the Feature Selection section for further details.
Profiling and the fitted schema#
Fit a |
|
Immutable, fitted description of a table's columns. |
|
Everything a fitted schema knows about one column. |
|
Training statistics of one column. |
Policy and configuration#
Complete, declarative description of how to profile a table. |
|
Select columns by exact name and/or shell-style pattern. |
|
Which provider answers one assessment question, with which parameters. |
|
How bin recommendations are computed for numeric features. |
|
How a drift reference is frozen and judged. |
|
Load a |
|
Write |
Assessments#
The recorded answer to one assessment for one feature. |
|
What a provider may read about one feature. |
|
What a provider returns: a state, reason codes and evidence. |
|
A named, versioned function that answers one kind of question. |
|
Name table of assessment providers. |
|
Name table of assessment providers. |
|
Register an assessment provider; usable as a decorator. |
|
Tabulate registered providers. |
Binning#
A frozen bin recommendation for one feature. |
|
Return the equal-width bin count that maximises Knuth's posterior. |
|
Build a |
Scikit-learn estimators#
Class inheritance

Fit a feature schema on the training data; pass data through unchanged. |
|
Drop features whose assessments are true, and columns with non-feature roles. |
|
Column selector for |
|
Rename columns with a plan frozen at fit time. |
|
A complete, frozen |
Pipeline lineage#
Trace the feature lineage of a fitted estimator. |
|
Traced feature graph of a fitted pipeline. |
|
How one transformer's outputs derive from its inputs. |
|
Values of transformed features summed back onto raw input features. |
Drift#
Frozen training distribution of every compared feature. |
|
Frozen reference buckets of one feature. |
Analysis routing#
Route every feature to the plots, summaries and tests that fit its kind. |
|
Recommend an ordered preprocessing chain per feature. |
|
Group features that share the same recommended chain. |
|
Vocabularies and errors#
Outcome of one assessment of one feature. |
|
Physical storage family of a column, read from its pandas dtype and values. |
|
Semantic kind of a feature: what analyses and treatments make sense. |
|
Role of a column in a modelling task; only |
|
How strongly a lineage edge is supported. |
|
How the outputs of one pipeline stage relate to its inputs. |
|
Base class of every error raised by |
|
A policy or configuration document is off contract (unknown key, wrong type, bad range). |
|
Data given after fitting does not match the fitted schema (missing, extra or retyped columns). |
|
Later data differs from the fitted schema and |
|
A persisted artefact was written by another, unsupported schema generation. |
|
A pipeline's feature topology cannot be traced or does not reconcile with its output. |