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);
}
};
System Information (please complete the following information):
Describe the bug
When loading a LightGBM model for scoring, I get the following error:
Screenshots, Code, Sample Projects
Stack Trace
Code that throws error:
Working code:
Model:
iris-lgbm.txt
Output Schema:
Additional context Add any other context about the problem here.