dotnet / dotnet/machinelearning
How to make fast LightGBM Predictions in C# with a model from LightGBM c++/cli file
- Dominant language
- C#
- Stars
- 9.4k
- Forks
- 2k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 11
Description
Hello,
I've successfully created a model using LightGBM CLI, specifically the C/C++ version. Now, I'm facing the task of performing predictions from a C# application. I've written the following code, but unfortunately, I'm encountering difficulties in getting it to work.
I've attempted various approaches, but having a simple example would be incredibly helpful.
Thank you in advance for your assistance.
Best regards,
Wil
```
using Microsoft.ML;
using System;
using System.Collections.Generic;
using System.Linq;
class ProgramWithMLNet
{
static void Main()
{
var mlContext = new MLContext();
// Load the trained model
var model = mlContext.Model.Load(@"Path to a model that has been created with LightGBM CLI", out var modelSchema);
// Prepare input data for prediction
var input = new MyInputDataClass // Please replace this with your input data class
{
_data = new double[] { 0.1, .2, .3 }
};
// Make a prediction
var predictionEngine = mlContext.Model.CreatePredictionEngine(model);
var prediction = predictionEngine.Predict(input);
// Display the prediction result
Console.WriteLine("Prediction: " + prediction);
}
}
class MyInputDataClass
{
public double[] _data = null;
}
class MyOutputDataClass
{
double _result = 0;
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.