Skip to content

Using PlattCalibratorTransformer with custon name for Score Column #4700

@antoniovs1029

Description

@antoniovs1029

Issue

  • What did you do?
    I tried to create a model with a PlattCalibratorEstimator that uses a scoreColumnName with a name different from "Score" (as done through this API)

  • What happened?
    After fitting the estimator, and while trying to transform the input dataview, the following exception is thrown:
    System.InvalidOperationException: 'The data to calibrate contains no 'Score' column'

  • What did you expect?
    The model to work the same way as if I had used the name "Score" for my score column

Furthermore, I couldn't find any sample or test that actually used the optional parameter scoreColumnName of PlattCalibratorEstimator, or the other parameters (such as labelColumnName). So adding such tests might be also necessary (if my PR #4700 gets in, then fixing this issue in here would also require to add onnx tests to check that PlattCalibrator with custom scoreColumnName is saved correctly to onnx). Checking if this problem also occurs in the other CalibratorTransformers would also be relevant.

Notice that a simple workaround for this would be to copy the column that holds the score into a new column called Score, and specify Score as the scoreColumnName.

Source code / logs

In EXAMPLE 1 I show that it works if my score column is named "Score". But if I change the name, then it doesn't work.

using Microsoft.ML;

namespace Platt2
{
    public static class Platt2
    {

        class ModelInput
        {
            public bool Label { get; set; }
            public float Score { get; set; }
        }

        class ModelInput2
        {
            public bool Label { get; set; }
            public float ScoreX { get; set; }
        }

        public static void Main()
        {
            var mlContext = new MLContext(seed: 0);

            // EXAMPLE 1 - Works
            IDataView data = mlContext.Data.LoadFromEnumerable<ModelInput>(
                new ModelInput[]
                {
                                new ModelInput { Score = 10, Label = true },
                                new ModelInput { Score = 15, Label = false },
                }
            );

            var calibratorEstimator = mlContext.BinaryClassification.Calibrators
                .Platt();

            var calibratorTransformer = calibratorEstimator.Fit(data);
            var finalData = calibratorTransformer.Transform(data);
            var prev = finalData.Preview();


            // EXAMPLE 2 - Doesn't Work
            IDataView data2 = mlContext.Data.LoadFromEnumerable<ModelInput2>(
                new ModelInput2[]
                {
                                new ModelInput2 { ScoreX = 10, Label = true },
                                new ModelInput2 { ScoreX = 15, Label = false },
                }
            );

            calibratorEstimator = mlContext.BinaryClassification.Calibrators
                .Platt(scoreColumnName: "ScoreX");

            calibratorTransformer = calibratorEstimator.Fit(data2);
            finalData = calibratorTransformer.Transform(data2); // Throws exception
            prev = finalData.Preview();

        }

    }
}

Metadata

Metadata

Assignees

Labels

P1Priority of the issue for triage purpose: Needs to be fixed soon.bugSomething isn't workingloadsaveBugs related loading and saving data or models

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions