public void update(Example train) { prediction.update(train); }
@Test public void testConstruct() { int[] counts = { 0, 1, 3, 0, 4, 0 }; CategoricalPrediction prediction = new CategoricalPrediction(counts); assertEquals(FeatureType.CATEGORICAL, prediction.getFeatureType()); assertEquals(4, prediction.getMostProbableCategoryEncoding()); assertArrayEquals(toDoubles(counts), prediction.getCategoryCounts()); assertArrayEquals(new double[] {0.0, 0.125, 0.375, 0.0, 0.5, 0.0}, prediction.getCategoryProbabilities()); }
@Test public void testUpdate2() { NumericPrediction prediction = new NumericPrediction(1.5, 1); prediction.update(3.5, 3); assertEquals(3.0, prediction.getPrediction()); }
@Test public void testNumericVoteWeighted() { List<NumericPrediction> predictions = Arrays.asList( new NumericPrediction(1.0, 1), new NumericPrediction(3.0, 2), new NumericPrediction(6.0, 3) ); double[] weights = {3.0, 2.0, 1.0}; NumericPrediction vote = (NumericPrediction) WeightedPrediction.voteOnFeature(predictions, weights); assertEquals(FeatureType.NUMERIC, vote.getFeatureType()); assertEquals(15.0 / 6.0, vote.getPrediction()); }
@Test public void testCategoricalVoteWeighted() { List<CategoricalPrediction> predictions = Arrays.asList( new CategoricalPrediction(new int[]{0, 1, 2}), new CategoricalPrediction(new int[]{6, 2, 0}), new CategoricalPrediction(new int[]{0, 2, 0}) ); double[] weights = {1.0, 10.0, 1.0}; CategoricalPrediction vote = (CategoricalPrediction) WeightedPrediction.voteOnFeature(predictions, weights); assertEquals(FeatureType.CATEGORICAL, vote.getFeatureType()); assertEquals(0, vote.getMostProbableCategoryEncoding()); }
@Test public void testConstructFromProbability() { double[] probability = {0.0, 0.125, 0.375, 0.0, 0.5, 0.0 }; CategoricalPrediction prediction = new CategoricalPrediction(probability); assertEquals(FeatureType.CATEGORICAL, prediction.getFeatureType()); assertEquals(4, prediction.getMostProbableCategoryEncoding()); assertArrayEquals(probability, prediction.getCategoryProbabilities()); }
@Test public void testUpdate2() { int[] counts = { 0, 1, 3, 0, 4, 0 }; CategoricalPrediction prediction = new CategoricalPrediction(counts); prediction.update(0, 3); prediction.update(1, 9); assertArrayEquals(new double[] { 3, 10, 3, 0, 4, 0 }, prediction.getCategoryCounts()); assertArrayEquals(new double[] {0.15, 0.5, 0.15, 0.0, 0.2, 0.0}, prediction.getCategoryProbabilities()); }
@Test public void testConstruct() { NumericPrediction prediction = new NumericPrediction(1.5, 1); assertEquals(FeatureType.NUMERIC, prediction.getFeatureType()); assertEquals(1.5, prediction.getPrediction()); }
@Test public void testEquals() { NumericPrediction prediction = new NumericPrediction(1.5, 1); NumericPrediction prediction1 = new NumericPrediction(1.5, 2); assertEquals(prediction, prediction1); prediction1.update(2.0, 2); assertNotEquals(prediction, prediction1); prediction1.update(1.5, 4); assertNotEquals(prediction, prediction1); }
@Test public void testHashCode() { NumericPrediction prediction = new NumericPrediction(1.5, 1); assertEquals(1073217536, prediction.hashCode()); prediction.update(2.0, 2); assertEquals(1789394944, prediction.hashCode()); }
@Test public void testHashCode() { int[] counts = { 0, 1, 3, 0, 4, 0 }; CategoricalPrediction prediction = new CategoricalPrediction(counts); assertEquals(566115137, prediction.hashCode()); }
@Test public void testToString() { int[] counts = { 0, 1, 3, 0, 4, 0 }; CategoricalPrediction prediction = new CategoricalPrediction(counts); assertEquals(":[0.0, 0.125, 0.375, 0.0, 0.5, 0.0]", prediction.toString()); }
@Test public void testEquals() { int[] counts = { 0, 1, 3, 0, 4, 0 }; CategoricalPrediction prediction = new CategoricalPrediction(counts); assertNotEquals(prediction, new CategoricalPrediction(new int[] { 1, 2, 4, 5, 6, 7 })); }
public int getCount() { return prediction.getCount(); }
public CategoricalPrediction(int[] categoryCounts) { this(toDoubles(categoryCounts)); }
@Test public void testUpdate() { NumericPrediction prediction = new NumericPrediction(1.5, 1); Example example = new Example(NumericFeature.forValue(2.5)); prediction.update(example); assertEquals(2.0, prediction.getPrediction()); }
@Test public void testNumericVote() { List<NumericPrediction> predictions = Arrays.asList( new NumericPrediction(1.0, 1), new NumericPrediction(3.0, 2), new NumericPrediction(6.0, 3) ); double[] weights = {1.0, 1.0, 1.0}; NumericPrediction vote = (NumericPrediction) WeightedPrediction.voteOnFeature(predictions, weights); assertEquals(FeatureType.NUMERIC, vote.getFeatureType()); assertEquals(10.0 /3.0, vote.getPrediction()); }
@Test public void testCategoricalVote() { List<CategoricalPrediction> predictions = Arrays.asList( new CategoricalPrediction(new int[]{0, 1, 2}), new CategoricalPrediction(new int[]{6, 2, 0}), new CategoricalPrediction(new int[]{0, 2, 0}) ); double[] weights = {1.0, 1.0, 1.0}; CategoricalPrediction vote = (CategoricalPrediction) WeightedPrediction.voteOnFeature(predictions, weights); assertEquals(FeatureType.CATEGORICAL, vote.getFeatureType()); assertEquals(1, vote.getMostProbableCategoryEncoding()); }