Skip to content

Prior binary trainer requires float label column, but all other binary trainers require bool #3119

Closed
@eerhardt

Description

@eerhardt

Build a pipeline like:

            IEstimator<ITransformer> pipeline =
                MLContext.Transforms.ReplaceMissingValues("FixedAcidity", replacementMode: MissingValueReplacingEstimator.ReplacementMode.Mean)
                .Append(MLContext.FloatToBoolLabelNormalizer())
                .Append(MLContext.Transforms.Concatenate("Features",
                    new[]
                    {
                        "FixedAcidity",
                        "VolatileAcidity",
                        "CitricAcid",
                        "ResidualSugar",
                        "Chlorides",
                        "FreeSulfurDioxide",
                        "TotalSulfurDioxide",
                        "Density",
                        "Ph",
                        "Sulphates",
                        "Alcohol"}))
                .Append(MLContext.BinaryClassification.Trainers.Prior());

Scenario taken from XamlBrewer.Uwp.MachineLearningSample with the "Random" trainer changed to the "Prior" trainer.

When you try to fit this pipeline, you get an exception:

{System.ArgumentOutOfRangeException: Invalid type for Label column
Parameter name: data
 	Microsoft.ML.Core.dll!Microsoft.ML.Runtime.Contracts.CheckParam(Microsoft.ML.Runtime.IExceptionContext ctx, bool f, string paramName, string msg) Line 542	C#
 	Microsoft.ML.StandardTrainers.dll!Microsoft.ML.Trainers.PriorTrainer.Train(Microsoft.ML.TrainContext context) Line 235	C#
 	Microsoft.ML.StandardTrainers.dll!Microsoft.ML.Trainers.PriorTrainer.Microsoft.ML.ITrainer<Microsoft.ML.Trainers.PriorModelParameters>.Train(Microsoft.ML.TrainContext context) Line 274	C#
 	Microsoft.ML.StandardTrainers.dll!Microsoft.ML.Trainers.PriorTrainer.Fit(Microsoft.ML.IDataView input) Line 222	C#
 	Microsoft.ML.Data.dll!Microsoft.ML.Data.EstimatorChain<Microsoft.ML.ITransformer>.Fit(Microsoft.ML.IDataView input) Line 67	C#
>	XamlBrewer.Uwp.MachineLearningSample.exe!XamlBrewer.Uwp.MachineLearningSample.Models.BinaryClassificationModel.BuildAndTrain(string trainingDataPath, Microsoft.ML.IEstimator<Microsoft.ML.ITransformer> algorithm) Line 46	C#

It appears the Prior binary trainer can only take float labels:

_host.CheckParam(labelCol.Type == NumberDataViewType.Single, nameof(data), "Invalid type for Label column");

However, all other binary trainers require the label column to be a boolean.

cc @TomFinley

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions