Updated EmpiricalProbabilityCalibrationPoint to be named EmpiricalAndPredictedProbability.

This commit is contained in:
Vijay Sharma 2018-10-30 14:22:23 +00:00
Родитель 007eee5c78
Коммит 18f2983069
3 изменённых файлов: 16 добавлений и 16 удалений

Просмотреть файл

@ -775,7 +775,7 @@ namespace Microsoft.ML.Probabilistic.Learners
/// <param name="instanceSource">The instance source.</param>
/// <param name="predictions">The predictions.</param>
/// <returns>The computed empirical probability calibration curve.</returns>
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
TLabel positiveClassLabel,
TInstanceSource instanceSource,
IEnumerable<IDictionary<TLabel, double>> predictions)
@ -792,7 +792,7 @@ namespace Microsoft.ML.Probabilistic.Learners
/// <param name="binCount">The number of bins to use.</param>
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
/// <returns>The computed empirical probability calibration curve.</returns>
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
TLabel positiveClassLabel,
TInstanceSource instanceSource,
IEnumerable<IDictionary<TLabel, double>> predictions,
@ -810,7 +810,7 @@ namespace Microsoft.ML.Probabilistic.Learners
/// <param name="labelSource">The label source.</param>
/// <param name="predictions">The predictions.</param>
/// <returns>The computed empirical probability calibration curve.</returns>
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
TLabel positiveClassLabel,
TInstanceSource instanceSource,
TLabelSource labelSource,
@ -843,7 +843,7 @@ namespace Microsoft.ML.Probabilistic.Learners
/// <param name="binCount">The number of bins to use.</param>
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
/// <returns>The computed empirical probability calibration curve.</returns>
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
TLabel positiveClassLabel,
TInstanceSource instanceSource,
TLabelSource labelSource,
@ -916,7 +916,7 @@ namespace Microsoft.ML.Probabilistic.Learners
/// <param name="groundTruthInstances">The ground truth instances.</param>
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
/// <returns>The computed empirical probability calibration curve.</returns>
private IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
private IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
TLabel positiveClassLabel,
TInstanceSource instanceSource,
TLabelSource labelSource,
@ -957,12 +957,12 @@ namespace Microsoft.ML.Probabilistic.Learners
}
}
var calibrationCurve = new List<EmpiricalProbabilityCalibrationPoint>();
var calibrationCurve = new List<EmpiricalAndPredictedProbability>();
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]));
}

Просмотреть файл

@ -6,14 +6,14 @@ namespace Microsoft.ML.Probabilistic.Collections
{
using Microsoft.ML.Probabilistic.Utilities;
public struct EmpiricalProbabilityCalibrationPoint
public struct EmpiricalAndPredictedProbability
{
/// <summary>
/// Initializes a new instance of the <see cref="EmpiricalProbabilityCalibrationPoint"/> struct.
/// Initializes a new instance of the <see cref="EmpiricalAndPredictedProbability"/> struct.
/// </summary>
/// <param name="empiricalProbability">The empirical probability</param>
/// <param name="predictedProbability">The predicted probability</param>
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;
/// <summary>
/// Gets the string representation of this <see cref="EmpiricalProbabilityCalibrationPoint"/>.
/// Gets the string representation of this <see cref="EmpiricalAndPredictedProbability"/>.
/// </summary>
/// <returns>The string representation of the <see cref="EmpiricalProbabilityCalibrationPoint"/>.</returns>
/// <returns>The string representation of the <see cref="EmpiricalAndPredictedProbability"/>.</returns>
public override string ToString()
{
return $"{this.EmpiricalProbability}, {this.PredictedProbability}";
@ -49,7 +49,7 @@ namespace Microsoft.ML.Probabilistic.Collections
/// </returns>
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);
}

Просмотреть файл

@ -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);