public void NaiveCalibratorEstimator()
        {
            var calibratorTestData = GetCalibratorTestData();

            // naive calibrator
            var naiveCalibratorEstimator   = new NaiveCalibratorEstimator(Env, calibratorTestData.transformer.Model, "Label", "Features");
            var naiveCalibratorTransformer = naiveCalibratorEstimator.Fit(calibratorTestData.scoredData);

            // check data
            checkValidCalibratedData(calibratorTestData.scoredData, naiveCalibratorTransformer);

            //test estimator
            TestEstimatorCore(calibratorTestData.pipeline, calibratorTestData.data);

            Done();
        }
Beispiel #2
0
        public void NaiveCalibratorEstimator()
        {
            var calibratorTestData = GetCalibratorTestData();

            // naive calibrator
            var naiveCalibratorEstimator   = new NaiveCalibratorEstimator(Env);
            var naiveCalibratorTransformer = naiveCalibratorEstimator.Fit(calibratorTestData.ScoredData);

            // check data
            CheckValidCalibratedData(calibratorTestData.ScoredData, naiveCalibratorTransformer);

            //test estimator
            TestEstimatorCore(calibratorTestData.Pipeline, calibratorTestData.Data);

            Done();
        }
        public void TestNonStandardCalibratorEstimatorClasses()
        {
            var mlContext = new MLContext(0);

            // Store different possible variations of calibrator data classes.
            IDataView[] dataArray = new IDataView[]
            {
                mlContext.Data.LoadFromEnumerable <CalibratorTestInputReversedOrder>(
                    new CalibratorTestInputReversedOrder[]
                {
                    new CalibratorTestInputReversedOrder {
                        Score = 10, Label = true
                    },
                    new CalibratorTestInputReversedOrder {
                        Score = 15, Label = false
                    }
                }),
                mlContext.Data.LoadFromEnumerable <CalibratorTestInputUniqueScoreColumnName>(
                    new CalibratorTestInputUniqueScoreColumnName[]
                {
                    new CalibratorTestInputUniqueScoreColumnName {
                        Label = true, ScoreX = 10
                    },
                    new CalibratorTestInputUniqueScoreColumnName {
                        Label = false, ScoreX = 15
                    }
                }),
                mlContext.Data.LoadFromEnumerable <CalibratorTestInputReversedOrderAndUniqueScoreColumnName>(
                    new CalibratorTestInputReversedOrderAndUniqueScoreColumnName[]
                {
                    new CalibratorTestInputReversedOrderAndUniqueScoreColumnName {
                        ScoreX = 10, Label = true
                    },
                    new CalibratorTestInputReversedOrderAndUniqueScoreColumnName {
                        ScoreX = 15, Label = false
                    }
                })
            };

            // When label and/or score columns are different from their default names ("Label" and "Score", respectively), they
            // need to be manually defined as done below.
            // Successful training of estimators and transforming with transformers indicate correct label and score columns
            // have been found.
            for (int i = 0; i < dataArray.Length; i++)
            {
                // Test PlattCalibratorEstimator
                var calibratorPlattEstimator = new PlattCalibratorEstimator(Env,
                                                                            scoreColumnName: i > 0 ? "ScoreX" : DefaultColumnNames.Score);
                var calibratorPlattTransformer = calibratorPlattEstimator.Fit(dataArray[i]);
                calibratorPlattTransformer.Transform(dataArray[i]);

                // Test FixedPlattCalibratorEstimator
                var calibratorFixedPlattEstimator = new FixedPlattCalibratorEstimator(Env,
                                                                                      scoreColumn: i > 0 ? "ScoreX" : DefaultColumnNames.Score);
                var calibratorFixedPlattTransformer = calibratorFixedPlattEstimator.Fit(dataArray[i]);
                calibratorFixedPlattTransformer.Transform(dataArray[i]);

                // Test NaiveCalibratorEstimator
                var calibratorNaiveEstimator = new NaiveCalibratorEstimator(Env,
                                                                            scoreColumn: i > 0 ? "ScoreX" : DefaultColumnNames.Score);
                var calibratorNaiveTransformer = calibratorNaiveEstimator.Fit(dataArray[i]);
                calibratorNaiveTransformer.Transform(dataArray[i]);

                // Test IsotonicCalibratorEstimator
                var calibratorIsotonicEstimator = new IsotonicCalibratorEstimator(Env,
                                                                                  scoreColumn: i > 0 ? "ScoreX" : DefaultColumnNames.Score);
                var calibratorIsotonicTransformer = calibratorIsotonicEstimator.Fit(dataArray[i]);
                calibratorIsotonicTransformer.Transform(dataArray[i]);
            }
        }