PrototypeExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
Prototype-based explainer that explains predictions using similar examples.
Implements: ILocalExplainer<T, PrototypeExplanation<T>>
For Beginners
Sometimes the best explanation is an example! This explainer answers “Why this prediction?” with “Because it’s similar to these examples.”
How it works:
- Maintain a set of “prototypes” (representative examples from training data)
- For a new prediction, find the most similar prototypes
- Explain the prediction based on these similar examples
Types of prototype explanations:
- Nearest neighbors: Show the K closest training examples
- Same-class prototypes: Show similar examples with the same prediction
- Contrast prototypes: Show similar examples with different predictions
Why prototypes are useful:
- Intuitive: “This loan was approved because it’s similar to John’s approved loan”
- Concrete: Shows actual examples, not abstract feature weights
- Trustworthy: Users can verify the similarity themselves
Example use cases:
- Medical diagnosis: “This case is similar to these past cases that were diagnosed as…”
- Credit decisions: “Your application is similar to these approved/denied applications”
- Image classification: “This image looks like these training images of cats”
Constructors
| Constructor | Summary |
|---|---|
PrototypeExplainer(Func<Matrix<T>, Vector<T>> predictFunction, Matrix<T> prototypes, Vector<T> prototypeLabels, int numNeighbors, DistanceMetric distanceMetric, string[] featureNames, string[] prototypeNames) |
Initializes a new Prototype explainer. |
Properties
| Property | Summary |
|---|---|
bool SupportsGlobalExplanations { get; } |
|
bool SupportsLocalExplanations { get; } |
|
string MethodName { get; } |
Methods
| Method | Summary |
|---|---|
PrototypeExplanation<T> Explain(Vector<T> instance) |
Explains a prediction using similar prototypes. |
PrototypeExplanation<T>[] ExplainBatch(Matrix<T> instances) |