/** * <summary> The predict method takes an Instance as an input and returns the entry of distribution which has the maximum value.</summary> * * <param name="instance">Instance to make prediction.</param> * <returns>The entry of distribution which has the maximum value.</returns> */ public override string Predict(Instance.Instance instance) { if (instance is CompositeInstance compositeInstance) { var possibleClassLabels = compositeInstance.GetPossibleClassLabels(); return(_distribution.GetMaxItem(possibleClassLabels)); } return(_distribution.GetMaxItem()); }
/** * <summary> The predict method takes an {@link Instance} as an input and loops through the {@link ArrayList} of {@link DecisionTree}s. * Makes prediction for the items of that ArrayList and returns the maximum item of that ArrayList.</summary> * * <param name="instance">Instance to make prediction.</param> * <returns>The maximum prediction of a given Instance.</returns> */ public override string Predict(Instance.Instance instance) { var distribution = new DiscreteDistribution(); foreach (var tree in _forest) { distribution.AddItem(tree.Predict(instance)); } return(distribution.GetMaxItem()); }
/** * <summary> The predict method takes an Instance as an input. First it gets the size of prior distribution and loops this size times. * Then it gets the possible class labels and and calculates metric value. At the end, it returns the class which has the * maximum value of metric.</summary> * * <param name="instance">{@link Instance} to predict.</param> * <returns>The class which has the maximum value of metric.</returns> */ public override string Predict(Instance.Instance instance) { string predictedClass; var maxMetric = double.MinValue; int size; if (instance is CompositeInstance compositeInstance) { predictedClass = compositeInstance.GetPossibleClassLabels()[0]; size = compositeInstance.GetPossibleClassLabels().Count; } else { predictedClass = priorDistribution.GetMaxItem(); size = priorDistribution.Count; } for (var i = 0; i < size; i++) { string ci; if (instance is CompositeInstance compositeInstance1) { ci = compositeInstance1.GetPossibleClassLabels()[i]; } else { ci = priorDistribution.GetItem(i); } if (priorDistribution.ContainsItem(ci)) { var metric = CalculateMetric(instance, ci); if (metric > maxMetric) { maxMetric = metric; predictedClass = ci; } } } return(predictedClass); }
public void TestGetMaxItem1() { Assert.AreEqual("item1", smallDistribution.GetMaxItem()); }