Petter T
Petter T

Reputation: 3627

How to predict/score XGBoost or LightGBM in .NET Framework 4.6.1 application

I have a machine learning problem where I have obtained very good results on training/test data using both LightGBM and XGBoost. The next step is to obtain predictions from one of these models into an existing C# application (.NET Framework 4.6.1) Is there any library that can help me do this? What I have tried so far:

Any suggestions, or do I have to wait for ML.NET to fix the bug?

Upvotes: 2

Views: 3484

Answers (1)

Eric Erhardt
Eric Erhardt

Reputation: 2456

I was able to use LightGBM in a net461 console application. The above bug only occurs if you are using packages.config to manage your NuGet packages. In order to work around the listed bug in the LightGBM nuget package, you can take one of the following approaches:

  1. Use a new "SDK-style" .csproj, but set the TargetFramework to net461.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.ML.LightGBM" Version="0.3.0" />
  </ItemGroup>

  <ItemGroup>
    <None Update="iris-data.txt">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

  1. Change your normal .NET Framework .csproj to use <PackageReference> instead of packages.config. You can do this in the Package Manager Settings under Tools -> NuGet Package Manager menu. "Default package management format". You can refer to the Migrate from packages.config to PackageReference document for more info.

  <ItemGroup>
    <PackageReference Include="Microsoft.ML">
      <Version>0.3.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.ML.LightGBM">
      <Version>0.3.0</Version>
    </PackageReference>
  </ItemGroup>

Upvotes: 3

Related Questions