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:
features (tuple[FeatureReference, ...])
policy (DriftPolicy)
See also
FeatureSchema.auditStructural (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
Xwith 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_ratioandstatus(stable,warn,drift,insufficient,missing_column,type_changed,not_applicable).
- Parameters:
X (DataFrame)
- Return type:
- 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
Xwithpolicywhen None.- policyFeaturePolicy, mapping, path or None, default=None
Used to profile
Xwhenschemais None; itsdriftsection configures the reference.- columnssequence of str or None, default=None
Columns to compare; defaults to the
role="feature"columns.
- Returns:
- ReferenceProfile
The reference.
- Parameters:
X (DataFrame)
schema (FeatureSchema | None)
policy (Any)
- Return type:
- classmethod from_dict(data)[source]#
Rebuild a reference from
to_dictoutput.- Parameters:
- datamapping
Stored form.
- Returns:
- ReferenceProfile
The reference.
- Raises:
- IncompatibleSchemaError
For another generation or artefact type.
- Parameters:
- Return type:
- 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:
- Return type:
- 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:
- policy: DriftPolicy[source]#