dotnet / dotnet/machinelearning

OVA-PriorPredictor fails

Open
#5,575 1 comment 0 reactions 0 assignees View on GitHub
area-Trainers bug
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

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:
```c#
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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.