@Override public boolean isPositive(Example example) { CategoricalFeature feature = (CategoricalFeature) example.getFeature(getFeatureNumber()); if (feature == null) { return defaultDecision; } int encoding = feature.getEncoding(); if (encoding >= activeCategoryEncodings.size()) { return defaultDecision; } return activeCategoryEncodings.get(encoding); }
@Override public void update(Example train) { CategoricalFeature target = (CategoricalFeature) train.getTarget(); update(target.getEncoding(), 1); }
static double accuracy(DecisionForest forest, JavaRDD<Example> examples) { long total = examples.count(); if (total == 0) { return 0.0; } long correct = examples.filter(example -> { CategoricalPrediction prediction = (CategoricalPrediction) forest.predict(example); CategoricalFeature target = (CategoricalFeature) example.getTarget(); return prediction.getMostProbableCategoryEncoding() == target.getEncoding(); }).count(); return (double) correct / total; }
.collect(Collectors.groupingBy(f -> ((CategoricalFeature) f).getEncoding(), Collectors.counting())) ).collect().stream().map(p -> {
@Test public void testFeature() { CategoricalFeature f = CategoricalFeature.forEncoding(1); assertEquals(FeatureType.CATEGORICAL, f.getFeatureType()); assertEquals(1, f.getEncoding()); assertEquals(f, CategoricalFeature.forEncoding(1)); // Not necessary for correctness to assert this, but fairly important for performance assertSame(f, CategoricalFeature.forEncoding(1)); }
@Override public boolean isPositive(Example example) { CategoricalFeature feature = (CategoricalFeature) example.getFeature(getFeatureNumber()); if (feature == null) { return defaultDecision; } int encoding = feature.getEncoding(); if (encoding >= activeCategoryEncodings.size()) { return defaultDecision; } return activeCategoryEncodings.get(encoding); }
@Override public void update(Example train) { CategoricalFeature target = (CategoricalFeature) train.getTarget(); update(target.getEncoding(), 1); }
.collect(Collectors.groupingBy(f -> ((CategoricalFeature) f).getEncoding(), Collectors.counting())) ).collect().stream().map(p -> {