public class LIMEBase extends Object implements TabularExplainer<Regressor>
LIMEColumnar
. For plain text data use LIMEText
.
See:
Ribeiro MT, Singh S, Guestrin C. "Why should I trust you?: Explaining the predictions of any classifier" Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining 2016.
Modifier and Type | Field and Description |
---|---|
static double |
DISTANCE_DELTA |
protected static RegressionEvaluator |
evaluator |
protected SparseTrainer<Regressor> |
explanationTrainer |
protected Model<Label> |
innerModel |
protected double |
kernelWidth |
protected int |
numSamples |
protected long |
numTrainingExamples |
protected static OutputFactory<Regressor> |
regressionFactory |
protected SplittableRandom |
rng |
static double |
WIDTH_CONSTANT |
Constructor and Description |
---|
LIMEBase(SplittableRandom rng,
Model<Label> innerModel,
SparseTrainer<Regressor> explanationTrainer,
int numSamples)
Constructs a LIME explainer for a model which uses tabular data (i.e., no special treatment for text features).
|
Modifier and Type | Method and Description |
---|---|
LIMEExplanation |
explain(Example<Label> example)
Explain why the supplied
Example is classified a certain way. |
protected com.oracle.labs.mlrg.olcut.util.Pair<LIMEExplanation,List<Example<Regressor>>> |
explainWithSamples(Example<Label> example) |
static double |
kernelDist(double input,
double width)
Calculates an RBF kernel of a specific width.
|
static double |
measureDistance(ImmutableFeatureMap fMap,
long numTrainingExamples,
SparseVector input,
SparseVector sample)
Measures the distance between an input point and a sampled point.
|
static Example<Label> |
samplePoint(Random rng,
ImmutableFeatureMap fMap,
long numTrainingExamples,
SparseVector input)
Samples a single example from the supplied feature map and input vector.
|
protected SparseModel<Regressor> |
trainExplainer(Example<Regressor> target,
List<Example<Regressor>> samples)
Trains the explanation model using the supplied sampled data and the input example.
|
static Regressor |
transformOutput(Prediction<Label> prediction)
Transforms a
Prediction for a multiclass problem into a Regressor
output which represents the probability for each class. |
public static final double WIDTH_CONSTANT
public static final double DISTANCE_DELTA
protected static final OutputFactory<Regressor> regressionFactory
protected static final RegressionEvaluator evaluator
protected final SplittableRandom rng
protected final SparseTrainer<Regressor> explanationTrainer
protected final int numSamples
protected final long numTrainingExamples
protected final double kernelWidth
public LIMEBase(SplittableRandom rng, Model<Label> innerModel, SparseTrainer<Regressor> explanationTrainer, int numSamples)
rng
- The rng to use for sampling.innerModel
- The model to explain.explanationTrainer
- The sparse trainer used to explain predictions.numSamples
- The number of samples to generate for an explanation.public LIMEExplanation explain(Example<Label> example)
TabularExplainer
Example
is classified a certain way.explain
in interface TabularExplainer<Regressor>
example
- The Example to explain.protected com.oracle.labs.mlrg.olcut.util.Pair<LIMEExplanation,List<Example<Regressor>>> explainWithSamples(Example<Label> example)
public static Example<Label> samplePoint(Random rng, ImmutableFeatureMap fMap, long numTrainingExamples, SparseVector input)
rng
- The rng to use.fMap
- The feature map describing the domain of the features.numTrainingExamples
- The number of training examples the fMap has seen.input
- The input sparse vector to use.protected SparseModel<Regressor> trainExplainer(Example<Regressor> target, List<Example<Regressor>> samples)
The labels are usually the predicted probabilities from the real model.
target
- The input example to explain.samples
- The sampled data around the input.public static double kernelDist(double input, double width)
input
- The input value.width
- The width of the kernel.public static double measureDistance(ImmutableFeatureMap fMap, long numTrainingExamples, SparseVector input, SparseVector sample)
This distance function takes into account categorical and real values. It uses the hamming distance for categoricals and the euclidean distance for real values.
fMap
- The feature map used to determine if a feature is categorical or real.numTrainingExamples
- The number of training examples the fMap has seen.input
- The input point.sample
- The sampled point.public static Regressor transformOutput(Prediction<Label> prediction)
Prediction
for a multiclass problem into a Regressor
output which represents the probability for each class.
Used as the target for LIME Models.
prediction
- A multiclass prediction object. Must contain probabilities.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.