Skip to content

Commit 8dd53e1

Browse files
committed
Api clean up for LightGBM. The cleanup includes:
- Changing all abbreviated parameters to full names (i.e. numThreads->NumberOfThreads) - Updating column parameters to have Name if thats what they represent (LabelColumn->LabelColumnName). - Updated baseline files to reflect these changes which are semantical and should not have any computational difference. This fixes dotnet#2618
1 parent 6e9023f commit 8dd53e1

File tree

36 files changed

+342
-337
lines changed

36 files changed

+342
-337
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Ranking/LightGbm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public static void Example()
2020

2121
// Create the Estimator pipeline. For simplicity, we will train a small tree with 4 leaves and 2 boosting iterations.
2222
var pipeline = mlContext.Ranking.Trainers.LightGbm(
23-
numLeaves: 4,
24-
minDataPerLeaf: 10,
23+
leafCount: 4,
24+
minimumDataPerLeaf: 10,
2525
learningRate: 0.1,
26-
numBoostRound: 2);
26+
numberOfIterations: 2);
2727

2828
// Fit this Pipeline to the Training Data.
2929
var model = pipeline.Fit(split.TrainSet);

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Ranking/LightGbmWithOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public static void Example()
2323
var pipeline = mlContext.Ranking.Trainers.LightGbm(
2424
new Options
2525
{
26-
NumLeaves = 4,
27-
MinDataPerLeaf = 10,
26+
NumberOfLeaves = 4,
27+
MinimumDataPerLeaf = 10,
2828
LearningRate = 0.1,
29-
NumBoostRound = 2,
29+
NumberOfIterations = 2,
3030
Booster = new TreeBooster.Options
3131
{
3232
FeatureFraction = 0.9

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/LightGbm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public static void Example()
3535
var pipeline = mlContext.Transforms.Concatenate("Features", featureNames)
3636
.Append(mlContext.Regression.Trainers.LightGbm(
3737
labelColumnName: labelName,
38-
numLeaves: 4,
39-
minDataPerLeaf: 6,
38+
leafCount: 4,
39+
minimumDataPerLeaf: 6,
4040
learningRate: 0.001));
4141

4242
// Fit this pipeline to the training data.

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/LightGbmWithOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static void Example()
3939
.Append(mlContext.Regression.Trainers.LightGbm(new Options
4040
{
4141
LabelColumnName = labelName,
42-
NumLeaves = 4,
43-
MinDataPerLeaf = 6,
42+
NumberOfLeaves = 4,
43+
MinimumDataPerLeaf = 6,
4444
LearningRate = 0.001,
4545
Booster = new GossBooster.Options
4646
{

docs/samples/Microsoft.ML.Samples/Static/LightGBMRegression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public static void LightGbmRegression()
3838
.Append(r => (r.label, score: mlContext.Regression.Trainers.LightGbm(
3939
r.label,
4040
r.features,
41-
numLeaves: 4,
42-
minDataPerLeaf: 6,
41+
numberOfLeaves: 4,
42+
minimumDataPerLeaf: 6,
4343
learningRate: 0.001,
4444
onFit: p => pred = p)
4545
)

src/Microsoft.ML.LightGBM.StaticPipe/LightGbmStaticExtensions.cs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public static class LightGbmStaticExtensions
2121
/// <param name="label">The label column.</param>
2222
/// <param name="features">The features column.</param>
2323
/// <param name="weights">The weights column.</param>
24-
/// <param name="numLeaves">The number of leaves to use.</param>
25-
/// <param name="numBoostRound">Number of iterations.</param>
26-
/// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
24+
/// <param name="numberOfLeaves">The number of leaves to use.</param>
25+
/// <param name="minimumDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
2726
/// <param name="learningRate">The learning rate.</param>
27+
/// <param name="numberOfIterations">Number of iterations.</param>
2828
/// <param name="onFit">A delegate that is called every time the
2929
/// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
3030
/// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
@@ -39,19 +39,19 @@ public static class LightGbmStaticExtensions
3939
/// </example>
4040
public static Scalar<float> LightGbm(this RegressionCatalog.RegressionTrainers catalog,
4141
Scalar<float> label, Vector<float> features, Scalar<float> weights = null,
42-
int? numLeaves = null,
43-
int? minDataPerLeaf = null,
42+
int? numberOfLeaves = null,
43+
int? minimumDataPerLeaf = null,
4444
double? learningRate = null,
45-
int numBoostRound = Options.Defaults.NumBoostRound,
45+
int numberOfIterations = Options.Defaults.NumberOfIterations,
4646
Action<LightGbmRegressionModelParameters> onFit = null)
4747
{
48-
CheckUserValues(label, features, weights, numLeaves, minDataPerLeaf, learningRate, numBoostRound, onFit);
48+
CheckUserValues(label, features, weights, numberOfLeaves, minimumDataPerLeaf, learningRate, numberOfIterations, onFit);
4949

5050
var rec = new TrainerEstimatorReconciler.Regression(
5151
(env, labelName, featuresName, weightsName) =>
5252
{
53-
var trainer = new LightGbmRegressorTrainer(env, labelName, featuresName, weightsName, numLeaves,
54-
minDataPerLeaf, learningRate, numBoostRound);
53+
var trainer = new LightGbmRegressorTrainer(env, labelName, featuresName, weightsName, numberOfLeaves,
54+
minimumDataPerLeaf, learningRate, numberOfIterations);
5555
if (onFit != null)
5656
return trainer.WithOnFitDelegate(trans => onFit(trans.Model));
5757
return trainer;
@@ -122,11 +122,13 @@ public static Scalar<float> LightGbm(this RegressionCatalog.RegressionTrainers c
122122
/// ]]></format>
123123
/// </example>
124124
public static (Scalar<float> score, Scalar<float> probability, Scalar<bool> predictedLabel) LightGbm(this BinaryClassificationCatalog.BinaryClassificationTrainers catalog,
125-
Scalar<bool> label, Vector<float> features, Scalar<float> weights = null,
125+
Scalar<bool> label,
126+
Vector<float> features,
127+
Scalar<float> weights = null,
126128
int? numLeaves = null,
127129
int? minDataPerLeaf = null,
128130
double? learningRate = null,
129-
int numBoostRound = Options.Defaults.NumBoostRound,
131+
int numBoostRound = Options.Defaults.NumberOfIterations,
130132
Action<CalibratedModelParametersBase<LightGbmBinaryModelParameters, PlattCalibrator>> onFit = null)
131133
{
132134
CheckUserValues(label, features, weights, numLeaves, minDataPerLeaf, learningRate, numBoostRound, onFit);
@@ -194,9 +196,9 @@ public static (Scalar<float> score, Scalar<float> probability, Scalar<bool> pred
194196
/// <param name="features">The features column.</param>
195197
/// <param name="groupId">The groupId column.</param>
196198
/// <param name="weights">The weights column.</param>
197-
/// <param name="numLeaves">The number of leaves to use.</param>
198-
/// <param name="numBoostRound">Number of iterations.</param>
199-
/// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
199+
/// <param name="numberOfLeaves">The number of leaves to use.</param>
200+
/// <param name="numberOfIterations">Number of iterations.</param>
201+
/// <param name="minimumDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
200202
/// <param name="learningRate">The learning rate.</param>
201203
/// <param name="onFit">A delegate that is called every time the
202204
/// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
@@ -206,21 +208,24 @@ public static (Scalar<float> score, Scalar<float> probability, Scalar<bool> pred
206208
/// <returns>The set of output columns including in order the predicted binary classification score (which will range
207209
/// from negative to positive infinity), the calibrated prediction (from 0 to 1), and the predicted label.</returns>
208210
public static Scalar<float> LightGbm<TVal>(this RankingCatalog.RankingTrainers catalog,
209-
Scalar<float> label, Vector<float> features, Key<uint, TVal> groupId, Scalar<float> weights = null,
210-
int? numLeaves = null,
211-
int? minDataPerLeaf = null,
211+
Scalar<float> label,
212+
Vector<float> features,
213+
Key<uint, TVal> groupId,
214+
Scalar<float> weights = null,
215+
int? numberOfLeaves = null,
216+
int? minimumDataPerLeaf = null,
212217
double? learningRate = null,
213-
int numBoostRound = Options.Defaults.NumBoostRound,
218+
int numberOfIterations = Options.Defaults.NumberOfIterations,
214219
Action<LightGbmRankingModelParameters> onFit = null)
215220
{
216-
CheckUserValues(label, features, weights, numLeaves, minDataPerLeaf, learningRate, numBoostRound, onFit);
221+
CheckUserValues(label, features, weights, numberOfLeaves, minimumDataPerLeaf, learningRate, numberOfIterations, onFit);
217222
Contracts.CheckValue(groupId, nameof(groupId));
218223

219224
var rec = new TrainerEstimatorReconciler.Ranker<TVal>(
220225
(env, labelName, featuresName, groupIdName, weightsName) =>
221226
{
222-
var trainer = new LightGbmRankingTrainer(env, labelName, featuresName, groupIdName, weightsName, numLeaves,
223-
minDataPerLeaf, learningRate, numBoostRound);
227+
var trainer = new LightGbmRankingTrainer(env, labelName, featuresName, groupIdName, weightsName, numberOfLeaves,
228+
minimumDataPerLeaf, learningRate, numberOfIterations);
224229

225230
if (onFit != null)
226231
return trainer.WithOnFitDelegate(trans => onFit(trans.Model));
@@ -279,10 +284,10 @@ public static Scalar<float> LightGbm<TVal>(this RankingCatalog.RankingTrainers c
279284
/// <param name="label">The label, or dependent variable.</param>
280285
/// <param name="features">The features, or independent variables.</param>
281286
/// <param name="weights">The weights column.</param>
282-
/// <param name="numLeaves">The number of leaves to use.</param>
283-
/// <param name="numBoostRound">Number of iterations.</param>
284-
/// <param name="minDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
287+
/// <param name="numberOfLeaves">The number of leaves to use.</param>
288+
/// <param name="minimumDataPerLeaf">The minimal number of documents allowed in a leaf of the tree, out of the subsampled data.</param>
285289
/// <param name="learningRate">The learning rate.</param>
290+
/// <param name="numberOfIterations">Number of iterations.</param>
286291
/// <param name="onFit">A delegate that is called every time the
287292
/// <see cref="Estimator{TInShape, TOutShape, TTransformer}.Fit(DataView{TInShape})"/> method is called on the
288293
/// <see cref="Estimator{TInShape, TOutShape, TTransformer}"/> instance created out of this. This delegate will receive
@@ -301,19 +306,19 @@ public static (Vector<float> score, Key<uint, TVal> predictedLabel)
301306
Key<uint, TVal> label,
302307
Vector<float> features,
303308
Scalar<float> weights = null,
304-
int? numLeaves = null,
305-
int? minDataPerLeaf = null,
309+
int? numberOfLeaves = null,
310+
int? minimumDataPerLeaf = null,
306311
double? learningRate = null,
307-
int numBoostRound = Options.Defaults.NumBoostRound,
312+
int numberOfIterations = Options.Defaults.NumberOfIterations,
308313
Action<OvaModelParameters> onFit = null)
309314
{
310-
CheckUserValues(label, features, weights, numLeaves, minDataPerLeaf, learningRate, numBoostRound, onFit);
315+
CheckUserValues(label, features, weights, numberOfLeaves, minimumDataPerLeaf, learningRate, numberOfIterations, onFit);
311316

312317
var rec = new TrainerEstimatorReconciler.MulticlassClassifier<TVal>(
313318
(env, labelName, featuresName, weightsName) =>
314319
{
315-
var trainer = new LightGbmMulticlassTrainer(env, labelName, featuresName, weightsName, numLeaves,
316-
minDataPerLeaf, learningRate, numBoostRound);
320+
var trainer = new LightGbmMulticlassTrainer(env, labelName, featuresName, weightsName, numberOfLeaves,
321+
minimumDataPerLeaf, learningRate, numberOfIterations);
317322

318323
if (onFit != null)
319324
return trainer.WithOnFitDelegate(trans => onFit(trans.Model));

0 commit comments

Comments
 (0)