public void TestProbabilityCalibrationPlot()
        {
            const int Bins = 3;

            double[] plot = this.evaluator.ProbabilityCalibrationPlot(this.dataset, this.uncertainPredictions, 4, Bins);

            Assert.Equal(Bins, plot.Length);
            Assert.False(double.IsNaN(plot[0]));
            Assert.False(double.IsNaN(plot[1]));
            Assert.True(double.IsNaN(plot[2]));
            Assert.Equal(0, plot[0], CompareEps);
            Assert.Equal(2.0 / 3.0, plot[1], CompareEps);
        }
Exemple #2
0
        public void TestBernoulliPointEstimator()
        {
            var distribution = new Bernoulli(0.25);

            Assert.False(distribution.GetMode());
            Assert.False(PointEstimator.GetEstimate(distribution, Metrics.ZeroOneError));  // Mode
            Assert.False(distribution.GetMean() >= 0.5);
            Assert.False(PointEstimator.GetEstimate(distribution, Metrics.SquaredError));  // Mean
            Assert.False(PointEstimator.GetEstimate(distribution, Metrics.AbsoluteError)); // Median = Mode

            distribution = new Bernoulli(0.5);
            Assert.True(distribution.GetMode());
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.ZeroOneError));  // Mode
            Assert.True(distribution.GetMean() >= 0.5);
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.AbsoluteError)); // Median = Mode

            distribution = new Bernoulli(0.6);
            Assert.True(distribution.GetMode());
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.ZeroOneError));  // Mode
            Assert.True(distribution.GetMean() >= 0.5);
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(distribution, Metrics.AbsoluteError)); // Median = Mode

            Assert.Throws <ArgumentNullException>(() => PointEstimator.GetEstimate(distribution, null));

            // Test generic representation of distribution
            var genericDistribution = new Dictionary <bool, double> {
                { true, 0.25 }, { false, 0.75 }
            };                                                                                    // Order matters!

            Assert.False(PointEstimator.GetEstimate(genericDistribution, Metrics.ZeroOneError));  // Mode
            Assert.False(PointEstimator.GetEstimate(genericDistribution, Metrics.SquaredError));  // Mean
            Assert.False(PointEstimator.GetEstimate(genericDistribution, Metrics.AbsoluteError)); // Median = Mode

            genericDistribution = new Dictionary <bool, double> {
                { true, 0.5 }, { false, 0.5 }
            };
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.ZeroOneError));  // Mode
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.AbsoluteError)); // Median = Mode

            genericDistribution = new Dictionary <bool, double> {
                { true, 0.6 }, { false, 0.4 }
            };
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.ZeroOneError));  // Mode
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.SquaredError));  // Mean
            Assert.True(PointEstimator.GetEstimate(genericDistribution, Metrics.AbsoluteError)); // Median = Mode

            Assert.Throws <ArgumentNullException>(() => PointEstimator.GetEstimate(distribution, null));
        }