Skip to content

Input column 'PredictedLabel' doesn't contain key values metadata  #6587

Open
@luisquintanilla

Description

@luisquintanilla

System Information (please complete the following information):

  • OS & Version: Windows 11
  • ML.NET Version:
  • .NET Version: .NET 7

Describe the bug

When loading a LightGBM model for scoring, I get the following error:

Input column 'PredictedLabel' doesn't contain key values metadata (Parameter 'inputSchema')

Screenshots, Code, Sample Projects

Stack Trace

   at Microsoft.ML.Transforms.KeyToValueMappingEstimator.GetOutputSchema(SchemaShape inputSchema)
   at Microsoft.ML.Data.EstimatorChain`1.GetOutputSchema(SchemaShape inputSchema)
   at Microsoft.ML.Data.EstimatorChain`1.Fit(IDataView input)
   at Program.<Main>$(String[] args) in C:\Dev\LGBMLoadingSample\LGBMLoadingSample\Program.cs:line 22

Code that throws error:

using Microsoft.ML;
using Microsoft.ML.Data;

var ctx = new MLContext();

var modelPath = "iris-lgbm.txt";

var data = new[]
{
    new {SepalLength=5.1f, SepalWidth=3.5f,PetalLength=1.4f, PetalWidth=0.2f}
};

var dv = ctx.Data.LoadFromEnumerable(data);

using(var modelStream = new FileStream(modelPath,FileMode.Open))
{
    var pipeline =
        ctx.Transforms.Concatenate("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")
            .Append(ctx.MulticlassClassification.Trainers.LightGbm(modelStream), TransformerScope.Scoring)
            .Append(ctx.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

    var model = pipeline.Fit(dv);

    var predictions = model.Transform(dv);

    var predictionCol = predictions.GetColumn<string>("PredictedLabel");

    foreach(var pred in predictionCol)
    {
        Console.WriteLine(pred);
    }
};

Working code:

using(var modelStream = new FileStream(modelPath,FileMode.Open))
{
    var pipeline =
        ctx.Transforms.Concatenate("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")
            .Append(ctx.MulticlassClassification.Trainers.LightGbm(modelStream), TransformerScope.Scoring);

    var model = pipeline.Fit(dv);

    var predictions = model.Transform(dv);

    var predictionCol = predictions.GetColumn<uint>("PredictedLabel");

    foreach(var pred in predictionCol)
    {
        Console.WriteLine(pred);
    }
};

Model:

iris-lgbm.txt

Output Schema:

image

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions