use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.
the class DataUtilsTest method testDropLinearizedFeature.
@Test
void testDropLinearizedFeature() {
for (Type t : Type.values()) {
Feature target = TestUtils.getMockedFeature(t, new Value(1d));
List<Feature> features = new LinkedList<>();
features.add(TestUtils.getMockedNumericFeature());
features.add(target);
features.add(TestUtils.getMockedTextFeature("foo bar"));
features.add(TestUtils.getMockedNumericFeature());
Feature source = FeatureFactory.newCompositeFeature("composite", features);
Feature newFeature = DataUtils.dropOnLinearizedFeatures(target, source);
assertNotEquals(source, newFeature);
}
}
use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.
the class PmmlScorecardCategoricalLimeExplainerTest method getModel.
private PredictionProvider getModel() {
return inputs -> CompletableFuture.supplyAsync(() -> {
List<PredictionOutput> outputs = new ArrayList<>();
for (PredictionInput input1 : inputs) {
List<Feature> features1 = input1.getFeatures();
SimpleScorecardCategoricalExecutor pmmlModel = new SimpleScorecardCategoricalExecutor(features1.get(0).getValue().asString(), features1.get(1).getValue().asString());
PMML4Result result = pmmlModel.execute(scorecardCategoricalRuntime);
String score = "" + result.getResultVariables().get(SimpleScorecardCategoricalExecutor.TARGET_FIELD);
String reason1 = "" + result.getResultVariables().get(SimpleScorecardCategoricalExecutor.REASON_CODE1_FIELD);
String reason2 = "" + result.getResultVariables().get(SimpleScorecardCategoricalExecutor.REASON_CODE2_FIELD);
PredictionOutput predictionOutput = new PredictionOutput(List.of(new Output("score", Type.TEXT, new Value(score), 1d), new Output("reason1", Type.TEXT, new Value(reason1), 1d), new Output("reason2", Type.TEXT, new Value(reason2), 1d)));
outputs.add(predictionOutput);
}
return outputs;
});
}
use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.
the class LimeExplainerTest method testWithDataDistribution.
@Test
void testWithDataDistribution() throws InterruptedException, ExecutionException, TimeoutException {
Random random = new Random();
PerturbationContext perturbationContext = new PerturbationContext(4L, random, 1);
List<FeatureDistribution> featureDistributions = new ArrayList<>();
int nf = 4;
List<Feature> features = new ArrayList<>();
for (int i = 0; i < nf; i++) {
Feature numericalFeature = FeatureFactory.newNumericalFeature("f-" + i, Double.NaN);
features.add(numericalFeature);
List<Value> values = new ArrayList<>();
for (int r = 0; r < 4; r++) {
values.add(Type.NUMBER.randomValue(perturbationContext));
}
featureDistributions.add(new GenericFeatureDistribution(numericalFeature, values));
}
DataDistribution dataDistribution = new IndependentFeaturesDataDistribution(featureDistributions);
LimeConfig limeConfig = new LimeConfig().withDataDistribution(dataDistribution).withPerturbationContext(perturbationContext).withSamples(10);
LimeExplainer limeExplainer = new LimeExplainer(limeConfig);
PredictionInput input = new PredictionInput(features);
PredictionProvider model = TestUtils.getSumThresholdModel(random.nextDouble(), random.nextDouble());
PredictionOutput output = model.predictAsync(List.of(input)).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit()).get(0);
Prediction prediction = new SimplePrediction(input, output);
Map<String, Saliency> saliencyMap = limeExplainer.explainAsync(prediction, model).get(Config.INSTANCE.getAsyncTimeout(), Config.INSTANCE.getAsyncTimeUnit());
assertThat(saliencyMap).isNotNull();
String decisionName = "inside";
Saliency saliency = saliencyMap.get(decisionName);
assertThat(saliency).isNotNull();
}
use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.
the class TestUtils method getFixedOutputClassifier.
public static PredictionProvider getFixedOutputClassifier() {
return inputs -> supplyAsync(() -> {
List<PredictionOutput> outputs = new LinkedList<>();
for (PredictionInput ignored : inputs) {
Output output = new Output("class", Type.BOOLEAN, new Value(false), 1d);
outputs.add(new PredictionOutput(List.of(output)));
}
return outputs;
});
}
use of org.kie.kogito.explainability.model.Value in project kogito-apps by kiegroup.
the class TestUtils method getMockedTextFeature.
public static Feature getMockedTextFeature(String s) {
Feature f = mock(Feature.class);
when(f.getType()).thenReturn(Type.TEXT);
when(f.getName()).thenReturn("f-text");
Value value = mock(Value.class);
when(value.getUnderlyingObject()).thenReturn(s);
when(value.asNumber()).thenReturn(Double.NaN);
when(value.asString()).thenReturn(s);
when(f.getValue()).thenReturn(value);
return f;
}
Aggregations