trace_pipeline#
- scikitplot.feature_selection.trace_pipeline(estimator, input_features=None, *, X=None, trace_final=False)[source]#
Trace the feature lineage of a fitted estimator.
- Parameters:
- estimatorfitted estimator
A
Pipeline,ColumnTransformer,FeatureUnionor single transformer. A pipeline’s final step withouttransform(the model) is recorded by name and not traced.- input_featuressequence of str or None, default=None
Raw input names; defaults to
estimator.feature_names_in_(set when it was fitted on a DataFrame), elsex0, x1, ....- XDataFrame or array or None, default=None
Optional sample of training-like rows. Every stage is then run on it and its actual output width checked.
- trace_finalbool, default=False
A top-level pipeline’s last step with
predictis the model and is not traced, even when it also hastransform(LDA, KMeans). True traces it as a transformer.
- Returns:
- FeatureLineage
The traced graph.
- Raises:
- LineageError
If a stage’s traced count disagrees with its feature names or its actual output, or a stage’s width cannot be determined.
- sklearn.exceptions.NotFittedError
If the estimator is not fitted.
- Parameters:
- Return type:
See also
FeatureLineageQuery the result.
Examples
>>> import pandas as pd >>> from sklearn.compose import ColumnTransformer >>> from sklearn.preprocessing import OneHotEncoder, StandardScaler >>> from scikitplot.feature_selection import trace_pipeline >>> X = pd.DataFrame({"age": [20.0, 30.0, 40.0, 50.0], "city": list("abab")}) >>> ct = ColumnTransformer( ... [("num", StandardScaler(), ["age"]), ("cat", OneHotEncoder(), ["city"])] ... ).fit(X) >>> lineage = trace_pipeline(ct, X=X) >>> lineage.output_names ['num__age', 'cat__city_a', 'cat__city_b'] >>> lineage.origins("cat__city_b") ('city',) >>> lineage.attribute([0.2, 0.3, 0.5]).by_input.to_dict() {'age': 0.2, 'city': 0.8}