CounterfactualStoryboard
A Python library for generating and visualizing narrative sequences of counterfactual explanations.
CounterfactualStoryboard calculates the Shortest Path, Cheapest Path, and Most Actionable Path to reach a desired outcome, generating plain-language explanations and a beautiful decision storyboard.
Features
- Abstract Engine: Built on
dice-ml, but extensible to other counterfactual generation algorithms. - Narrative Generation: Uses Jinja2 templates to turn numeric feature changes into human-readable sentences.
- Dual Visualization: Outputs interactive HTML/Plotly dashboards or static Matplotlib figures.
- Model Agnostic: Works with
scikit-learn,TensorFlow,PyTorch, or any custom model via a simplepredict_fn.
Installation
pip install counterfactual_storyboard
Quickstart
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from counterfactual_storyboard import StoryboardExplainer, FeatureMetadata
# 1. Train your model
df = pd.read_csv("data.csv")
X = df.drop(columns=["target"])
y = df["target"]
model = RandomForestClassifier().fit(X, y)
# 2. Define Feature Metadata (Costs and Mutability)
metadata = FeatureMetadata(
continuous_features=["age", "balance", "credit_score"],
actionable_features=["balance"],
feature_costs={"age": 100, "balance": 1, "credit_score": 10}
)
# 3. Initialize Explainer
explainer = StoryboardExplainer(
predict_fn=model.predict_proba,
training_data=df,
target_column="target",
feature_metadata=metadata
)
# 4. Generate Storyboard for an instance
instance = X.iloc[0:1]
storyboard = explainer.generate_storyboard(instance, target_class=1)
# 5. Visualize
storyboard.show()
Metadata
Release files for counterfactual-storyboard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| counterfactual_storyboard-0.1.0.tar.gz | 9.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| counterfactual_storyboard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / counterfactual_storyboard-0.1.0.tar.gz
| Download URL | counterfactual_storyboard-0.1.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c60de3bf8aa6496fec5e4301fa6498aac4f7ae5be8b115ce143b29c36624659d
|
|
BLAKE2b-256 checksum How to use checksums |
88b5c12d541fad3f26e6b7e618ef6c7f7f7e9501fd91ffebc32027a46d4d8d51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / counterfactual_storyboard-0.1.0-py3-none-any.whl
| Download URL | counterfactual_storyboard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b7c9e265905e57521d13248eba4e758c293c465a4b5042a69ccf44c0cd525ac
|
|
BLAKE2b-256 checksum How to use checksums |
2997f8bdb4184a9f3b3970bcf1b8cfecbf619c60b7244aaf984275d25f0a53d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|