Skip to content

OVA-PriorPredictor fails #5575

Open
Open

Description

@justinormont

When placed in a One-vs-All (OVA), PriorPredictor throws a "Nullable object must have a value" error.

Error:

Unhandled exception. System.InvalidOperationException: Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Microsoft.ML.Data.SchemaBindablePredictorWrapperBase.SingleValueRowMapper.GetInputColumnRoles()+MoveNext()
   at Microsoft.ML.Data.RoleMappedSchema.MapFromNames(DataViewSchema schema, IEnumerable`1 roles, Boolean opt)
   at Microsoft.ML.Data.RoleMappedSchema..ctor(DataViewSchema schema, IEnumerable`1 roles, Boolean opt)
   at Microsoft.ML.Data.PredictedLabelScorerBase.BindingsImpl.ApplyToSchema(DataViewSchema input, ISchemaBindableMapper bindable, IHostEnvironment env)
   at Microsoft.ML.Data.PredictedLabelScorerBase..ctor(IHostEnvironment env, PredictedLabelScorerBase transform, IDataView newSource, String registrationName)
   at Microsoft.ML.Data.MulticlassClassificationScorer..ctor(IHostEnvironment env, MulticlassClassificationScorer transform, IDataView newSource)
   at Microsoft.ML.Data.MulticlassClassificationScorer.ApplyToDataCore(IHostEnvironment env, IDataView newSource)
   at Microsoft.ML.Data.RowToRowScorerBase.ApplyToData(IHostEnvironment env, IDataView newSource)
   at Microsoft.ML.Data.PredictionTransformerBase`1.Transform(IDataView input)
   at Microsoft.ML.Data.EstimatorChain`1.Fit(IDataView input)
   at Program.Main()

PriorPredictor does work properly when not in an OVA (aka, used as a normal binary trainer).

Repro:

See fiddle: https://dotnetfiddle.net/bs5hiw

Fiddle demonstrates:

  • Binary PriorPredictor is successful
  • OVA-AveragedPerceptron is successful
  • OVA-PriorPredictor fails

Relevant code:

var baselineMulticlassPipeline = mlContext.Transforms.Conversion.MapValueToKey("Label", "Label")
			.Append(mlContext.MulticlassClassification.Trainers.OneVersusAll(mlContext.BinaryClassification.Trainers.Prior(labelColumnName: "Label"), labelColumnName: "Label"));
		var multiclassModel = baselineMulticlassPipeline.Fit(split.TrainSet);

Cause:
PriorPredictor differs from other trainers in part as it doesn't take in a Features column (and only looks at the Label column). My first guess would be when wrapping the One-vs-All in an Estimators API, we missed the part that the Features column won't exist for the PriorPredictor.

Activity

  1. added
    bug
    on Jan 4, 2021
  2. justinormont commented on Jan 4, 2021

    @justinormont
    ContributorAuthor

    Why OVA-PriorPredictor:
    The PriorPredictor is good at establishing baseline metrics from which you can measure improvement. The trainer always guesses the largest class in your dataset. The PriorPredictor is trained on your training dataset and evaluated on your validation/test dataset(s) (or cross-validation), giving you a measure of how well a NOOP trainer performs, including factors like distribution drift and sampling/splitting variability.

    Docs: https://docs.microsoft.com/en-us/dotnet/api/microsoft.ml.standardtrainerscatalog.prior

    Nit bug -- "models" is misspelt here:

    /// This trainer uses the proportion of a label in the training set as the probability of that label.
    /// This trainer is often used as a baseline for other more sophisticated mdels.

  3. added
    area-Trainers
    and removed on Sep 8, 2026
  4. added
    green
    yellow
    on Sep 21, 2026
  5. svick commented on Nov 27, 2026

    @svick
    Member

    Triage: Keeping this open as a bug. Prior intentionally does not use a feature column, but OVA's multiclass scoring path assumes one exists and throws when binding the model.

    Adding a dummy Features column does not work around this, because the Prior transformer still reports no feature-column name.

    We should make this scoring path handle featureless predictors and add regression coverage for OneVersusAll(Prior()), while preserving standalone binary Prior behavior.

    Note

    This comment was written by GitHub Copilot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Trainersbuggreenyellow

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions