FeatureLineage#

class scikitplot.feature_selection.FeatureLineage(nodes, edges, stages, stage_inputs, input_ids, output_ids, estimator, final_estimator=None)[source]#

Traced feature graph of a fitted pipeline.

Parameters:
nodes, edges, stagestuples

Graph records (see FeatureNode, LineageEdge, StageRecord).

stage_inputstuple of (str, tuple of int)

Input node ids of every stage, in the order of stages.

input_ids, output_idstuple of int

Node ids of the raw inputs and of the final outputs (model inputs).

estimatorstr

Class name of the traced object.

final_estimatorstr or None

Class name of a pipeline’s final, non-transformer step.

Parameters:

See also

trace_pipeline

Build a lineage.

attribute(values, *, how='sum')[source]#

Aggregate per-output values (importances, SHAP values) onto raw inputs.

Parameters:
valuesarray-like, pandas.Series or mapping

1-D: one value per output (array aligned with output_names, or a Series/mapping keyed by output name). 2-D array or DataFrame: n_samples x n_outputs (a DataFrame is aligned by column name).

how{“sum”, “abs_sum”, “mean”, “max”}, default=”sum”

Aggregation over the outputs of one input.

Returns:
Attribution

Attributed and unattributed parts.

Raises:
ValueError

If the values do not align with the outputs.

Parameters:
Return type:

Attribution

Notes

An output is attributed only when it has exactly one raw origin and every edge on its paths is exact. Polynomial interactions, PCA components and unknown steps are reported in Attribution.unattributed instead of being split by a guess.

children(name, stage='input')[source]#

Return the immediate successors of a feature.

Parameters:
namestr

Feature name at stage.

stagestr, default=”input”

Stage path, "input" or "output".

Returns:
list of (stage, name)

Successor features.

Parameters:
Return type:

list[tuple[str, str]]

descendants(name, stage='input', *, to='output')[source]#

Return the features at stage to computed from name.

Parameters:
namestr

Feature name at stage.

stagestr, default=”input”

Stage of name.

tostr, default=”output”

Stage to walk forward to.

Returns:
tuple of str

Descendant names at to, in column order.

Parameters:
Return type:

tuple[str, …]

dropped()[source]#

Return the raw inputs that reach no output, with the stage that removed them.

Returns:
dict of str to str

Input name to the path of the stage that received its last surviving feature and did not pass it on (a selector, or a ColumnTransformer whose branches and remainder ignore the column).

Return type:

dict[str, str]

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

Serialise the lineage; "jsonl" writes one edge record per line.

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

json/yaml/toml hold the complete, reloadable document (verified by reading it back); jsonl holds the edge table (to_frame) for log pipelines.

Returns:
str

The document.

Parameters:

format (str)

Return type:

str

edges: tuple[LineageEdge, ...][source]#
estimator: str[source]#
final_estimator: str | None = None#
classmethod from_dict(data)[source]#

Rebuild a lineage from to_dict output.

Parameters:
datamapping

Stored form.

Returns:
FeatureLineage

The lineage.

Raises:
IncompatibleSchemaError

For another generation or artefact type.

ValueError

For an off-contract record.

Parameters:

data (Mapping[str, Any])

Return type:

FeatureLineage

history(name)[source]#

Return every leaf stage that touched the descendants of input name.

Parameters:
namestr

Raw input name.

Returns:
pandas.DataFrame

Columns stage, estimator, relation, quality and features (the names this input became at that stage), in pipeline order. Containers (pipelines, column transformers) are listed with estimator set to their class.

Parameters:

name (str)

Return type:

DataFrame

input_ids: tuple[int, ...][source]#
property input_names: list[str]#

Raw input names.

Type:

List of str

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

Parse a document written by dumps with json or yaml.

Parameters:
textstr

The document.

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

Format.

Returns:
FeatureLineage

The lineage.

Parameters:
Return type:

FeatureLineage

nodes: tuple[FeatureNode, ...][source]#
origins(name, stage='output', *, to='input')[source]#

Return the features at stage to that name is computed from.

Parameters:
namestr

Feature name at stage.

stagestr, default=”output”

Stage of name.

tostr, default=”input”

Stage to walk back to.

Returns:
tuple of str

Ancestor names at to, in that stage’s column order.

Parameters:
Return type:

tuple[str, …]

output_ids: tuple[int, ...][source]#
property output_names: list[str]#

Final output names (what the model sees), in column order.

Type:

List of str

parents(name, stage='output')[source]#

Return the immediate predecessors of a feature.

Parameters:
namestr

Feature name at stage.

stagestr, default=”output”

Stage path, "input" or "output".

Returns:
list of (stage, name)

Predecessor features, in input order.

Parameters:
Return type:

list[tuple[str, str]]

quality(name, stage='output')[source]#

Return the weakest lineage quality on any path from the inputs to name.

Parameters:
namestr

Feature name.

stagestr, default=”output”

Its stage.

Returns:
str

"exact", "mixed" or "unknown".

Parameters:
Return type:

str

stage_inputs: tuple[tuple[str, tuple[int, ...]], ...][source]#
property stage_paths: list[str]#

Paths of every traced stage, in trace order.

Type:

List of str

stage_summary()[source]#

Return one row per traced stage.

Returns:
pandas.DataFrame

Columns path, estimator, container, relation, quality, n_in, n_out, delta, observed_width, note.

Return type:

DataFrame

stages: tuple[StageRecord, ...][source]#
to_dict()[source]#

Return the persisted form.

Returns:
dict

A tree of the shared data model with schema_version.

Return type:

dict[str, Any]

to_frame()[source]#

Return every edge as a row.

Returns:
pandas.DataFrame

Columns stage, parent_stage, parent, child, relation, quality.

Return type:

DataFrame

treatments()[source]#

Return, per raw input, the chain of leaf transformers applied to it.

Returns:
pandas.DataFrame

Indexed by input name with steps (tuple of "path:Class"), n_outputs (model inputs derived from it) and status ("kept" or "dropped").

Return type:

DataFrame