зеркало из https://github.com/dotnet/infer.git
Updated EmpiricalProbabilityCalibrationPoint to be named EmpiricalAndPredictedProbability.
This commit is contained in:
Родитель
007eee5c78
Коммит
18f2983069
|
@ -775,7 +775,7 @@ namespace Microsoft.ML.Probabilistic.Learners
|
||||||
/// <param name="instanceSource">The instance source.</param>
|
/// <param name="instanceSource">The instance source.</param>
|
||||||
/// <param name="predictions">The predictions.</param>
|
/// <param name="predictions">The predictions.</param>
|
||||||
/// <returns>The computed empirical probability calibration curve.</returns>
|
/// <returns>The computed empirical probability calibration curve.</returns>
|
||||||
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
|
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
|
||||||
TLabel positiveClassLabel,
|
TLabel positiveClassLabel,
|
||||||
TInstanceSource instanceSource,
|
TInstanceSource instanceSource,
|
||||||
IEnumerable<IDictionary<TLabel, double>> predictions)
|
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="binCount">The number of bins to use.</param>
|
||||||
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
|
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
|
||||||
/// <returns>The computed empirical probability calibration curve.</returns>
|
/// <returns>The computed empirical probability calibration curve.</returns>
|
||||||
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
|
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
|
||||||
TLabel positiveClassLabel,
|
TLabel positiveClassLabel,
|
||||||
TInstanceSource instanceSource,
|
TInstanceSource instanceSource,
|
||||||
IEnumerable<IDictionary<TLabel, double>> predictions,
|
IEnumerable<IDictionary<TLabel, double>> predictions,
|
||||||
|
@ -810,7 +810,7 @@ namespace Microsoft.ML.Probabilistic.Learners
|
||||||
/// <param name="labelSource">The label source.</param>
|
/// <param name="labelSource">The label source.</param>
|
||||||
/// <param name="predictions">The predictions.</param>
|
/// <param name="predictions">The predictions.</param>
|
||||||
/// <returns>The computed empirical probability calibration curve.</returns>
|
/// <returns>The computed empirical probability calibration curve.</returns>
|
||||||
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
|
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
|
||||||
TLabel positiveClassLabel,
|
TLabel positiveClassLabel,
|
||||||
TInstanceSource instanceSource,
|
TInstanceSource instanceSource,
|
||||||
TLabelSource labelSource,
|
TLabelSource labelSource,
|
||||||
|
@ -843,7 +843,7 @@ namespace Microsoft.ML.Probabilistic.Learners
|
||||||
/// <param name="binCount">The number of bins to use.</param>
|
/// <param name="binCount">The number of bins to use.</param>
|
||||||
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
|
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
|
||||||
/// <returns>The computed empirical probability calibration curve.</returns>
|
/// <returns>The computed empirical probability calibration curve.</returns>
|
||||||
public IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
|
public IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
|
||||||
TLabel positiveClassLabel,
|
TLabel positiveClassLabel,
|
||||||
TInstanceSource instanceSource,
|
TInstanceSource instanceSource,
|
||||||
TLabelSource labelSource,
|
TLabelSource labelSource,
|
||||||
|
@ -916,7 +916,7 @@ namespace Microsoft.ML.Probabilistic.Learners
|
||||||
/// <param name="groundTruthInstances">The ground truth instances.</param>
|
/// <param name="groundTruthInstances">The ground truth instances.</param>
|
||||||
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
|
/// <param name="minBinInstanceCount">The minimal number of instances per bin. Defaults to 1.</param>
|
||||||
/// <returns>The computed empirical probability calibration curve.</returns>
|
/// <returns>The computed empirical probability calibration curve.</returns>
|
||||||
private IEnumerable<EmpiricalProbabilityCalibrationPoint> CalibrationCurve(
|
private IEnumerable<EmpiricalAndPredictedProbability> CalibrationCurve(
|
||||||
TLabel positiveClassLabel,
|
TLabel positiveClassLabel,
|
||||||
TInstanceSource instanceSource,
|
TInstanceSource instanceSource,
|
||||||
TLabelSource labelSource,
|
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++)
|
for (int bin = 0; bin < binCount; bin++)
|
||||||
{
|
{
|
||||||
if (predictedCount[bin] >= minBinInstanceCount)
|
if (predictedCount[bin] >= minBinInstanceCount)
|
||||||
{
|
{
|
||||||
calibrationCurve.Add(new EmpiricalProbabilityCalibrationPoint(
|
calibrationCurve.Add(new EmpiricalAndPredictedProbability(
|
||||||
(bin + 0.5) / binCount,
|
(bin + 0.5) / binCount,
|
||||||
(double)positiveClassCount[bin] / predictedCount[bin]));
|
(double)positiveClassCount[bin] / predictedCount[bin]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ namespace Microsoft.ML.Probabilistic.Collections
|
||||||
{
|
{
|
||||||
using Microsoft.ML.Probabilistic.Utilities;
|
using Microsoft.ML.Probabilistic.Utilities;
|
||||||
|
|
||||||
public struct EmpiricalProbabilityCalibrationPoint
|
public struct EmpiricalAndPredictedProbability
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="EmpiricalProbabilityCalibrationPoint"/> struct.
|
/// Initializes a new instance of the <see cref="EmpiricalAndPredictedProbability"/> struct.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="empiricalProbability">The empirical probability</param>
|
/// <param name="empiricalProbability">The empirical probability</param>
|
||||||
/// <param name="predictedProbability">The predicted probability</param>
|
/// <param name="predictedProbability">The predicted probability</param>
|
||||||
public EmpiricalProbabilityCalibrationPoint(double empiricalProbability, double predictedProbability)
|
public EmpiricalAndPredictedProbability(double empiricalProbability, double predictedProbability)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
this.EmpiricalProbability = empiricalProbability;
|
this.EmpiricalProbability = empiricalProbability;
|
||||||
|
@ -31,9 +31,9 @@ namespace Microsoft.ML.Probabilistic.Collections
|
||||||
public readonly double PredictedProbability;
|
public readonly double PredictedProbability;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the string representation of this <see cref="EmpiricalProbabilityCalibrationPoint"/>.
|
/// Gets the string representation of this <see cref="EmpiricalAndPredictedProbability"/>.
|
||||||
/// </summary>
|
/// </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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{this.EmpiricalProbability}, {this.PredictedProbability}";
|
return $"{this.EmpiricalProbability}, {this.PredictedProbability}";
|
||||||
|
@ -49,7 +49,7 @@ namespace Microsoft.ML.Probabilistic.Collections
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public override bool Equals(object obj)
|
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);
|
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()
|
public void CalibrationCurveTest()
|
||||||
{
|
{
|
||||||
// Curve for perfect predictions
|
// 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();
|
var actual = this.evaluator.CalibrationCurve(LabelSet[0], this.groundTruth, this.groundTruth).ToArray();
|
||||||
Xunit.Assert.Equal(expected, actual);
|
Xunit.Assert.Equal(expected, actual);
|
||||||
|
|
||||||
// Curve for imperfect predictions (one-versus-rest)
|
// 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();
|
actual = this.evaluator.CalibrationCurve(LabelSet[0], this.groundTruth, this.predictions).ToArray();
|
||||||
Xunit.Assert.Equal(expected, actual);
|
Xunit.Assert.Equal(expected, actual);
|
||||||
|
|
||||||
// Curve for imperfect predictions (3 bins)
|
// Curve for imperfect predictions (3 bins)
|
||||||
const int BinCount = 4;
|
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();
|
actual = this.evaluator.CalibrationCurve(LabelSet[0], this.groundTruth, this.predictions, BinCount).ToArray();
|
||||||
Xunit.Assert.Equal(expected, actual);
|
Xunit.Assert.Equal(expected, actual);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче