ReferenceProfile#

class scikitplot.feature_selection.ReferenceProfile(features, policy=<factory>)[source]#

Frozen training distribution of every compared feature.

Parameters:
featurestuple of FeatureReference

One reference per feature.

policyDriftPolicy

Bucketing and judging settings.

Parameters:

See also

FeatureSchema.audit

Structural (column/dtype) comparison.

Examples

>>> import numpy as np, pandas as pd
>>> from scikitplot.feature_selection import ReferenceProfile
>>> rng = np.random.default_rng(0)
>>> train = pd.DataFrame(
...     {"x": rng.normal(size=500), "c": rng.choice(list("ab"), 500)}
... )
>>> later = pd.DataFrame(
...     {"x": rng.normal(2.0, 1.0, 500), "c": rng.choice(list("ab"), 500)}
... )
>>> report = ReferenceProfile.fit(train).drift(later)
>>> report.set_index("feature")["status"].to_dict()
{'x': 'drift', 'c': 'stable'}
drift(X)[source]#

Compare X with the reference, feature by feature.

Parameters:
Xpandas.DataFrame

Current data.

Returns:
pandas.DataFrame

One row per reference feature with the columns feature, kind, method, n_reference, n_current, psi, js_distance, missing_reference, missing_current, missing_delta, unseen_ratio and status (stable, warn, drift, insufficient, missing_column, type_changed, not_applicable).

Parameters:

X (DataFrame)

Return type:

DataFrame

dumps(format='json')[source]#

Serialise the reference (verified by reading it back).

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

Format.

Returns:
str

The document.

Parameters:

format (str)

Return type:

str

features: tuple[FeatureReference, ...][source]#
classmethod fit(X, schema=None, *, policy=None, columns=None)[source]#

Freeze the reference buckets of X.

Parameters:
Xpandas.DataFrame

Reference (training) data.

schemaFeatureSchema or None, default=None

Kinds to use; profiled from X with policy when None.

policyFeaturePolicy, mapping, path or None, default=None

Used to profile X when schema is None; its drift section configures the reference.

columnssequence of str or None, default=None

Columns to compare; defaults to the role="feature" columns.

Returns:
ReferenceProfile

The reference.

Parameters:
Return type:

ReferenceProfile

classmethod from_dict(data)[source]#

Rebuild a reference from to_dict output.

Parameters:
datamapping

Stored form.

Returns:
ReferenceProfile

The reference.

Raises:
IncompatibleSchemaError

For another generation or artefact type.

Parameters:

data (Mapping[str, Any])

Return type:

ReferenceProfile

classmethod load(path, format=None)[source]#

Read a reference written by save.

Parameters:
pathstr or os.PathLike

Source file.

formatstr or None, default=None

Explicit format.

Returns:
ReferenceProfile

The reference.

Parameters:
  • path (Any)

  • format (str | None)

Return type:

ReferenceProfile

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

Parse a reference document.

Parameters:
textstr

The document.

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

Format.

Returns:
ReferenceProfile

The reference.

Parameters:
Return type:

ReferenceProfile

property names: list[str]#

Compared feature names.

Type:

List of str

policy: DriftPolicy[source]#
save(path, format=None)[source]#

Write the reference atomically.

Parameters:
pathstr or os.PathLike

Target file.

formatstr or None, default=None

Explicit format.

Returns:
pathlib.Path

The written path.

Parameters:
  • path (Any)

  • format (str | None)

Return type:

Path

to_dict()[source]#

Return the persisted form.

Return type:

dict[str, Any]