From 18f2983069002a3e8939bccf9ec758652ab2dd48 Mon Sep 17 00:00:00 2001 From: Vijay Sharma Date: Tue, 30 Oct 2018 14:22:23 +0000 Subject: [PATCH] Updated EmpiricalProbabilityCalibrationPoint to be named EmpiricalAndPredictedProbability. --- src/Learners/Classifier/ClassifierEvaluator.cs | 14 +++++++------- ...oint.cs => EmpiricalAndPredictedProbability.cs} | 12 ++++++------ .../LearnersTests/ClassifierEvaluatorTests.cs | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) rename src/Runtime/Core/Collections/{EmpiricalProbabilityCalibrationPoint.cs => EmpiricalAndPredictedProbability.cs} (87%) diff --git a/src/Learners/Classifier/ClassifierEvaluator.cs b/src/Learners/Classifier/ClassifierEvaluator.cs index b094e6d9..c35b164e 100644 --- a/src/Learners/Classifier/ClassifierEvaluator.cs +++ b/src/Learners/Classifier/ClassifierEvaluator.cs @@ -775,7 +775,7 @@ namespace Microsoft.ML.Probabilistic.Learners /// The instance source. /// The predictions. /// The computed empirical probability calibration curve. - public IEnumerable CalibrationCurve( + public IEnumerable CalibrationCurve( TLabel positiveClassLabel, TInstanceSource instanceSource, IEnumerable> predictions) @@ -792,7 +792,7 @@ namespace Microsoft.ML.Probabilistic.Learners /// The number of bins to use. /// The minimal number of instances per bin. Defaults to 1. /// The computed empirical probability calibration curve. - public IEnumerable CalibrationCurve( + public IEnumerable CalibrationCurve( TLabel positiveClassLabel, TInstanceSource instanceSource, IEnumerable> predictions, @@ -810,7 +810,7 @@ namespace Microsoft.ML.Probabilistic.Learners /// The label source. /// The predictions. /// The computed empirical probability calibration curve. - public IEnumerable CalibrationCurve( + public IEnumerable CalibrationCurve( TLabel positiveClassLabel, TInstanceSource instanceSource, TLabelSource labelSource, @@ -843,7 +843,7 @@ namespace Microsoft.ML.Probabilistic.Learners /// The number of bins to use. /// The minimal number of instances per bin. Defaults to 1. /// The computed empirical probability calibration curve. - public IEnumerable CalibrationCurve( + public IEnumerable CalibrationCurve( TLabel positiveClassLabel, TInstanceSource instanceSource, TLabelSource labelSource, @@ -916,7 +916,7 @@ namespace Microsoft.ML.Probabilistic.Learners /// The ground truth instances. /// The minimal number of instances per bin. Defaults to 1. /// The computed empirical probability calibration curve. - private IEnumerable CalibrationCurve( + private IEnumerable CalibrationCurve( TLabel positiveClassLabel, TInstanceSource instanceSource, TLabelSource labelSource, @@ -957,12 +957,12 @@ namespace Microsoft.ML.Probabilistic.Learners } } - var calibrationCurve = new List(); + var calibrationCurve = new List(); for (int bin = 0; bin < binCount; bin++) { if (predictedCount[bin] >= minBinInstanceCount) { - calibrationCurve.Add(new EmpiricalProbabilityCalibrationPoint( + calibrationCurve.Add(new EmpiricalAndPredictedProbability( (bin + 0.5) / binCount, (double)positiveClassCount[bin] / predictedCount[bin])); } diff --git a/src/Runtime/Core/Collections/EmpiricalProbabilityCalibrationPoint.cs b/src/Runtime/Core/Collections/EmpiricalAndPredictedProbability.cs similarity index 87% rename from src/Runtime/Core/Collections/EmpiricalProbabilityCalibrationPoint.cs rename to src/Runtime/Core/Collections/EmpiricalAndPredictedProbability.cs index c9ea5c0a..79639900 100644 --- a/src/Runtime/Core/Collections/EmpiricalProbabilityCalibrationPoint.cs +++ b/src/Runtime/Core/Collections/EmpiricalAndPredictedProbability.cs @@ -6,14 +6,14 @@ namespace Microsoft.ML.Probabilistic.Collections { using Microsoft.ML.Probabilistic.Utilities; - public struct EmpiricalProbabilityCalibrationPoint + public struct EmpiricalAndPredictedProbability { /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The empirical probability /// The predicted probability - public EmpiricalProbabilityCalibrationPoint(double empiricalProbability, double predictedProbability) + public EmpiricalAndPredictedProbability(double empiricalProbability, double predictedProbability) : this() { this.EmpiricalProbability = empiricalProbability; @@ -31,9 +31,9 @@ namespace Microsoft.ML.Probabilistic.Collections public readonly double PredictedProbability; /// - /// Gets the string representation of this . + /// Gets the string representation of this . /// - /// The string representation of the . + /// The string representation of the . public override string ToString() { return $"{this.EmpiricalProbability}, {this.PredictedProbability}"; @@ -49,7 +49,7 @@ namespace Microsoft.ML.Probabilistic.Collections /// public override bool Equals(object obj) { - if (obj is EmpiricalProbabilityCalibrationPoint calibrationPoint) + if (obj is EmpiricalAndPredictedProbability calibrationPoint) { return object.Equals(this.EmpiricalProbability, calibrationPoint.EmpiricalProbability) && object.Equals(this.PredictedProbability, calibrationPoint.PredictedProbability); } diff --git a/test/Learners/LearnersTests/ClassifierEvaluatorTests.cs b/test/Learners/LearnersTests/ClassifierEvaluatorTests.cs index 15e3a5e2..26864834 100644 --- a/test/Learners/LearnersTests/ClassifierEvaluatorTests.cs +++ b/test/Learners/LearnersTests/ClassifierEvaluatorTests.cs @@ -252,18 +252,18 @@ namespace Microsoft.ML.Probabilistic.Learners.Tests public void CalibrationCurveTest() { // Curve for perfect predictions - var expected = new[] { new EmpiricalProbabilityCalibrationPoint(0.25, 0.0), new EmpiricalProbabilityCalibrationPoint(0.75, 1.0) }; + var expected = new[] { new EmpiricalAndPredictedProbability(0.25, 0.0), new EmpiricalAndPredictedProbability(0.75, 1.0) }; var actual = this.evaluator.CalibrationCurve(LabelSet[0], this.groundTruth, this.groundTruth).ToArray(); Xunit.Assert.Equal(expected, actual); // Curve for imperfect predictions (one-versus-rest) - expected = new[] { new EmpiricalProbabilityCalibrationPoint(0.25, 0.75), new EmpiricalProbabilityCalibrationPoint(0.75, 0.0) }; + expected = new[] { new EmpiricalAndPredictedProbability(0.25, 0.75), new EmpiricalAndPredictedProbability(0.75, 0.0) }; actual = this.evaluator.CalibrationCurve(LabelSet[0], this.groundTruth, this.predictions).ToArray(); Xunit.Assert.Equal(expected, actual); // Curve for imperfect predictions (3 bins) const int BinCount = 4; - expected = new[] { new EmpiricalProbabilityCalibrationPoint(1 / 8.0, 0.75), new EmpiricalProbabilityCalibrationPoint(7 / 8.0, 0.0) }; + expected = new[] { new EmpiricalAndPredictedProbability(1 / 8.0, 0.75), new EmpiricalAndPredictedProbability(7 / 8.0, 0.0) }; actual = this.evaluator.CalibrationCurve(LabelSet[0], this.groundTruth, this.predictions, BinCount).ToArray(); Xunit.Assert.Equal(expected, actual);