-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LightGBM #392
Merged
Merged
LightGBM #392
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
be4c61d
LightGBM and test.
codemzs 38531ba
add test baselines and nuget source for lightGBM binaries.
codemzs d4afe1c
Add entrypoint for lightGBM.
codemzs 1a5f61d
add unsafe flag for release build.
codemzs 58fe9d1
update nuget version.
codemzs eb9cefb
make lightgbm test single threaded.
codemzs f35aee4
install gcc on OS machines to resolve dependencies on openmp thatis n…
codemzs e593935
PR comments. Leave BREW and GCC in bash script to verify macOS tests …
codemzs fd003b8
remove brew and gcc from build script.
codemzs 4051788
PR feedback.
codemzs 7f613be
disable test on macOS.
codemzs ec326dd
disable test on macOS.
codemzs 793e7f5
PR feedback.
codemzs 695cea4
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageDescription>ML.NET component for LightGBM</PackageDescription> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../Microsoft.ML/Microsoft.ML.nupkgproj" /> | ||
<PackageReference Include="LightGBM" Version="$(LightGBMPackageVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
5 changes: 5 additions & 0 deletions
5
pkg/Microsoft.ML.LightGBM/Microsoft.ML.LightGBM.symbols.nupkgproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project DefaultTargets="Pack"> | ||
|
||
<Import Project="Microsoft.ML.LightGBM.nupkgproj" /> | ||
|
||
</Project> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.ML.Runtime; | ||
using Microsoft.ML.Runtime.Data; | ||
using Microsoft.ML.Runtime.EntryPoints; | ||
using Microsoft.ML.Runtime.FastTree; | ||
using Microsoft.ML.Runtime.Internal.Calibration; | ||
using Microsoft.ML.Runtime.Internal.Internallearn; | ||
using Microsoft.ML.Runtime.LightGBM; | ||
using Microsoft.ML.Runtime.Model; | ||
|
||
[assembly: LoadableClass(LightGbmBinaryTrainer.Summary, typeof(LightGbmBinaryTrainer), typeof(LightGbmArguments), | ||
new[] { typeof(SignatureBinaryClassifierTrainer), typeof(SignatureTrainer), typeof(SignatureTreeEnsembleTrainer) }, | ||
"LightGBM Binary Classification", LightGbmBinaryTrainer.LoadNameValue, LightGbmBinaryTrainer.ShortName, DocName = "trainer/LightGBM.md")] | ||
|
||
[assembly: LoadableClass(typeof(IPredictorProducing<float>), typeof(LightGbmBinaryPredictor), null, typeof(SignatureLoadModel), | ||
"LightGBM Binary Executor", | ||
LightGbmBinaryPredictor.LoaderSignature)] | ||
|
||
[assembly: LoadableClass(typeof(void), typeof(LightGbm), null, typeof(SignatureEntryPointModule), "LightGBM")] | ||
|
||
namespace Microsoft.ML.Runtime.LightGBM | ||
{ | ||
public sealed class LightGbmBinaryPredictor : FastTreePredictionWrapper | ||
{ | ||
public const string LoaderSignature = "LightGBMBinaryExec"; | ||
public const string RegistrationName = "LightGBMBinaryPredictor"; | ||
private static VersionInfo GetVersionInfo() | ||
{ | ||
// REVIEW: can we decouple the version from FastTree predictor version ? | ||
return new VersionInfo( | ||
modelSignature: "LGBBINCL", | ||
// verWrittenCur: 0x00010001, // Initial | ||
// verWrittenCur: 0x00010002, // _numFeatures serialized | ||
// verWrittenCur: 0x00010003, // Ini content out of predictor | ||
//verWrittenCur: 0x00010004, // Add _defaultValueForMissing | ||
verWrittenCur: 0x00010005, // Categorical splits. | ||
verReadableCur: 0x00010004, | ||
verWeCanReadBack: 0x00010001, | ||
loaderSignature: LoaderSignature); | ||
} | ||
|
||
protected override uint VerNumFeaturesSerialized { get { return 0x00010002; } } | ||
|
||
protected override uint VerDefaultValueSerialized { get { return 0x00010004; } } | ||
|
||
protected override uint VerCategoricalSplitSerialized { get { return 0x00010005; } } | ||
|
||
internal LightGbmBinaryPredictor(IHostEnvironment env, FastTree.Internal.Ensemble trainedEnsemble, int featureCount, string innerArgs) | ||
: base(env, RegistrationName, trainedEnsemble, featureCount, innerArgs) | ||
{ | ||
} | ||
|
||
private LightGbmBinaryPredictor(IHostEnvironment env, ModelLoadContext ctx) | ||
: base(env, RegistrationName, ctx, GetVersionInfo()) | ||
{ | ||
} | ||
|
||
protected override void SaveCore(ModelSaveContext ctx) | ||
{ | ||
base.SaveCore(ctx); | ||
ctx.SetVersionInfo(GetVersionInfo()); | ||
} | ||
|
||
public static IPredictorProducing<float> Create(IHostEnvironment env, ModelLoadContext ctx) | ||
{ | ||
Contracts.CheckValue(env, nameof(env)); | ||
env.CheckValue(ctx, nameof(ctx)); | ||
ctx.CheckAtModel(GetVersionInfo()); | ||
var predictor = new LightGbmBinaryPredictor(env, ctx); | ||
ICalibrator calibrator; | ||
ctx.LoadModelOrNull<ICalibrator, SignatureLoadModel>(env, out calibrator, @"Calibrator"); | ||
if (calibrator == null) | ||
return predictor; | ||
return new CalibratedPredictor(env, predictor, calibrator); | ||
} | ||
|
||
public override PredictionKind PredictionKind { get { return PredictionKind.BinaryClassification; } } | ||
} | ||
|
||
public sealed class LightGbmBinaryTrainer : LightGbmTrainerBase<float, IPredictorWithFeatureWeights<float>> | ||
{ | ||
public const string Summary = "LightGBM Binary Classifier"; | ||
public const string LoadNameValue = "LightGBMBinary"; | ||
public const string ShortName = "LightGBM"; | ||
|
||
public LightGbmBinaryTrainer(IHostEnvironment env, LightGbmArguments args) | ||
: base(env, args, PredictionKind.BinaryClassification, "LGBBINCL") | ||
{ | ||
} | ||
|
||
public override IPredictorWithFeatureWeights<float> CreatePredictor() | ||
{ | ||
Host.Check(TrainedEnsemble != null, "The predictor cannot be created before training is complete"); | ||
var innerArgs = LightGbmInterfaceUtils.JoinParameters(Options); | ||
var pred = new LightGbmBinaryPredictor(Host, TrainedEnsemble, FeatureCount, innerArgs); | ||
var cali = new PlattCalibrator(Host, -0.5, 0); | ||
return new FeatureWeightsCalibratedPredictor(Host, pred, cali); | ||
} | ||
|
||
protected override void CheckDataValid(IChannel ch, RoleMappedData data) | ||
{ | ||
Host.AssertValue(ch); | ||
base.CheckDataValid(ch, data); | ||
var labelType = data.Schema.Label.Type; | ||
if (!(labelType.IsBool || labelType.IsKey || labelType == NumberType.R4)) | ||
{ | ||
throw ch.ExceptParam(nameof(data), | ||
$"Label column '{data.Schema.Label.Name}' is of type '{labelType}', but must be key, boolean or R4."); | ||
} | ||
} | ||
|
||
protected override void CheckAndUpdateParametersBeforeTraining(IChannel ch, RoleMappedData data, float[] labels, int[] groups) | ||
{ | ||
Options["objective"] = "binary"; | ||
// Add default metric. | ||
if (!Options.ContainsKey("metric")) | ||
Options["metric"] = "binary_logloss"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// A component to train an LightGBM model. | ||
/// </summary> | ||
public static partial class LightGbm | ||
{ | ||
[TlcModule.EntryPoint( | ||
Name = "Trainers.LightGbmBinaryClassifier", | ||
Desc = "Train an LightGBM binary class model", | ||
UserName = LightGbmBinaryTrainer.Summary, | ||
ShortName = LightGbmBinaryTrainer.ShortName)] | ||
public static CommonOutputs.BinaryClassificationOutput TrainBinary(IHostEnvironment env, LightGbmArguments input) | ||
{ | ||
Contracts.CheckValue(env, nameof(env)); | ||
var host = env.Register("TrainLightGBM"); | ||
host.CheckValue(input, nameof(input)); | ||
EntryPointUtils.CheckInputArgs(host, input); | ||
|
||
return LearnerEntryPointsUtils.Train<LightGbmArguments, CommonOutputs.BinaryClassificationOutput>(host, input, | ||
() => new LightGbmBinaryTrainer(host, input), | ||
getLabel: () => LearnerEntryPointsUtils.FindColumn(host, input.TrainingData.Schema, input.LabelColumn), | ||
getWeight: () => LearnerEntryPointsUtils.FindColumn(host, input.TrainingData.Schema, input.WeightColumn)); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LightGbmArguments is LearnerInputBaseWithGroupId, but we don't pass getGroup function... #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean but this is really a port of LightGBM so please keep comments within the scope of the PR>
In reply to: 197549696 [](ancestors = 197549696)