Exemple #1
0
        public void TestLogisticRegressionWithStats()
        {
            (IEstimator <ITransformer> pipe, IDataView dataView) = GetBinaryClassificationPipeline();

            pipe = pipe.Append(ML.BinaryClassification.Trainers.LogisticRegression(
                                   new LogisticRegression.Options
            {
                ShowTrainingStats = true,
                StdComputer       = new ComputeLRTrainingStdThroughHal(),
            }));

            var transformer = pipe.Fit(dataView) as TransformerChain <BinaryPredictionTransformer <CalibratedModelParametersBase <LinearBinaryModelParameters, PlattCalibrator> > >;

            var linearModel = transformer.LastTransformer.Model.SubModel as LinearBinaryModelParameters;
            var stats       = linearModel.Statistics;

            LinearModelStatistics.TryGetBiasStatistics(stats, 2, out float stdError, out float zScore, out float pValue);

            CompareNumbersWithTolerance(stdError, 0.250672936);
            CompareNumbersWithTolerance(zScore, 7.97852373);

            var scoredData = transformer.Transform(dataView);

            var coeffcients = stats.GetCoefficientStatistics(linearModel, scoredData.Schema["Features"], 100);

            Assert.Equal(19, coeffcients.Length);

            foreach (var coefficient in coeffcients)
            {
                Assert.True(coefficient.StandardError < 1.0);
            }
        }
Exemple #2
0
        public void TestLogisticRegressionNoStats()
        {
            (IEstimator <ITransformer> pipe, IDataView dataView) = GetBinaryClassificationPipeline();

            pipe = pipe.Append(new LogisticRegression(Env, "Label", "Features", advancedSettings: s => { s.ShowTrainingStats = true; }));
            var transformerChain = pipe.Fit(dataView) as TransformerChain <BinaryPredictionTransformer <ParameterMixingCalibratedPredictor> >;

            var linearModel = transformerChain.LastTransformer.Model.SubPredictor as LinearBinaryModelParameters;
            var stats       = linearModel.Statistics;

            LinearModelStatistics.TryGetBiasStatistics(stats, 2, out float stdError, out float zScore, out float pValue);

            Assert.Equal(0f, stdError);
            Assert.Equal(0f, zScore);
        }
Exemple #3
0
        public void TestLogisticRegressionNoStats()
        {
            (IEstimator <ITransformer> pipe, IDataView dataView) = GetBinaryClassificationPipeline();

            pipe = pipe.Append(ML.BinaryClassification.Trainers.LogisticRegression(new LogisticRegression.Options {
                ShowTrainingStats = true
            }));
            var transformerChain = pipe.Fit(dataView) as TransformerChain <BinaryPredictionTransformer <CalibratedModelParametersBase <LinearBinaryModelParameters, PlattCalibrator> > >;

            var linearModel = transformerChain.LastTransformer.Model.SubModel as LinearBinaryModelParameters;
            var stats       = linearModel.Statistics;

            LinearModelStatistics.TryGetBiasStatistics(stats, 2, out float stdError, out float zScore, out float pValue);

            Assert.Equal(0f, stdError);
            Assert.Equal(0f, zScore);
        }
        public void TestLogisticRegressionStats_MKL()
        {
            (IEstimator <ITransformer> pipe, IDataView dataView) = GetBinaryClassificationPipeline();

            pipe = pipe.Append(new LogisticRegression(Env, "Label", "Features", advancedSettings: s => {
                s.ShowTrainingStats = true;
                s.StdComputer       = new ComputeLRTrainingStdThroughHal();
            }));

            var transformerChain = pipe.Fit(dataView) as TransformerChain <BinaryPredictionTransformer <ParameterMixingCalibratedPredictor> >;

            var linearModel = transformerChain.LastTransformer.Model.SubPredictor as LinearBinaryPredictor;
            var stats       = linearModel.Statistics;

            LinearModelStatistics.TryGetBiasStatistics(stats, 2, out float stdError, out float zScore, out float pValue);

            CompareNumbersWithTolerance(stdError, 0.250672936);
            CompareNumbersWithTolerance(zScore, 7.97852373);
        }