FeaturePolicy#

class scikitplot.feature_selection.FeaturePolicy(roles=(), kinds=(), tags=(), assessments=(), overrides=(), binning=<factory>, drift=<factory>, on_missing_column='raise')[source]#

Complete, declarative description of how to profile a table.

Parameters:
rolesmapping of role to ColumnRule-like, default=()

Columns with a role other than "feature" (target, drop, identifier, weight, group, time). A column matched by two roles is an error.

kindsmapping of column to kind, default=()

Explicit semantic kinds that replace inference (for example a numeric zip_code declared "categorical_nominal", or "text").

tagsmapping of tag to ColumnRule-like, default=()

Free user labels ("one_hot", "engineered", "sensitive"); a column can carry many tags. Tags never change inference.

assessmentsmapping of name to AssessmentSpec-like, default=()

Merged over DEFAULT_ASSESSMENTS by name.

overridesmapping of column to mapping of assessment to bool, default=()

Manual answers. The inferred answer is kept next to the override.

binningBinningPolicy or mapping, default=BinningPolicy()

Bin recommendation settings.

driftDriftPolicy or mapping, default=DriftPolicy()

Drift reference settings.

on_missing_column{“raise”, “ignore”}, default=”raise”

What to do when roles, kinds, tags or overrides name a column that is not in the data.

Parameters:

See also

load_policy

Read a policy from TOML, YAML or JSON.

dump_policy

Write a policy, verified by reading it back.

profile_features

Fit a schema from a DataFrame and a policy.

Notes

User note. Keep one policy per project in version control. Its digest is recorded in every fitted schema, so you can tell which configuration produced a result.

Developer note. Stored containers are sorted tuples of pairs; the *_map properties return fresh dictionaries.

Examples

>>> from scikitplot.feature_selection import FeaturePolicy
>>> policy = FeaturePolicy(
...     roles={"target": ["churn"]},
...     assessments={
...         "skewed": {"provider": "skewed", "params": {"threshold": 0.75}}
...     },
... )
>>> policy.assessments_map["skewed"].params_dict["threshold"]
0.75
>>> FeaturePolicy.from_dict(policy.to_dict()) == policy
True
assessments: tuple[tuple[str, AssessmentSpec], ...] = ()#
property assessments_map: dict[str, AssessmentSpec]#

Assessment name to spec, defaults included.

Type:

dict

binning: BinningPolicy[source]#
check_columns(names)[source]#

Refuse kinds/overrides keys absent from names (unless ignored).

Parameters:
namessequence of str

Column names of the data.

Raises:
PolicyError

If a key is missing and on_missing_column="raise".

Parameters:

names (Sequence[str])

Return type:

None

property digest: str#

SHA-256 of the canonical JSON form; equal policies share it.

Type:

str

drift: DriftPolicy[source]#
dumps(format='toml')[source]#

Serialise the policy, verified by reading it back.

Parameters:
format{“toml”, “yaml”, “json”}, default=”toml”

Output format.

Returns:
str

The document.

Raises:
PolicyError

If the document would not load back equal to this policy.

Parameters:

format (str)

Return type:

str

classmethod from_dict(data)[source]#

Build a policy from its config form, checking every field first.

Parameters:
datamapping

A document as produced by to_dict or written by hand; every key is optional except that schema_version, when given, must be the supported generation.

Returns:
FeaturePolicy

The policy.

Raises:
PolicyError

For an unknown key, a wrong type or an out-of-range value.

IncompatibleSchemaError

For another schema_version.

Parameters:

data (Mapping[str, Any])

Return type:

FeaturePolicy

kinds: tuple[tuple[str, str], ...] = ()#
property kinds_map: dict[str, str]#

Column to declared kind.

Type:

dict

classmethod loads(text, format='toml')[source]#

Parse a policy document.

Parameters:
textstr

The document.

format{“toml”, “yaml”, “json”}, default=”toml”

Input format.

Returns:
FeaturePolicy

The policy.

Parameters:
Return type:

FeaturePolicy

on_missing_column: str = 'raise'#
overrides: tuple[tuple[str, tuple[tuple[str, bool], ...]], ...] = ()#
property overrides_map: dict[str, dict[str, bool]]#

Column to manual assessment answers.

Type:

dict

resolve_roles(names)[source]#

Return the role of every column in names.

Parameters:
namessequence of str

Column names of the data.

Returns:
dict

Column to role value; unlisted columns are "feature".

Raises:
PolicyError

If a column matches two roles, or a named column is missing and on_missing_column="raise".

Parameters:

names (Sequence[str])

Return type:

dict[str, str]

resolve_tags(names)[source]#

Return the tags of every column in names.

Parameters:
namessequence of str

Column names of the data.

Returns:
dict

Column to sorted tuple of tags (empty when untagged).

Parameters:

names (Sequence[str])

Return type:

dict[str, tuple[str, …]]

roles: tuple[tuple[str, ColumnRule], ...] = ()#
property roles_map: dict[str, ColumnRule]#

Role name to column rule.

Type:

dict

tags: tuple[tuple[str, ColumnRule], ...] = ()#
property tags_map: dict[str, ColumnRule]#

Tag to column rule.

Type:

dict

to_dict()[source]#

Return the canonical config form, defaults included.

Returns:
dict

A tree of the shared data model with schema_version.

Return type:

dict[str, Any]