Skip to content

Commit d8957fd

Browse files
committed
Go through all places once
1 parent d64a4ae commit d8957fd

24 files changed

+190
-195
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/FastTreeRegression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static void Example()
2929
// We will train a FastTreeRegression model with 1 tree on these two columns to predict Age.
3030
string outputColumnName = "Features";
3131
var pipeline = ml.Transforms.Concatenate(outputColumnName, new[] { "Parity", "Induced" })
32-
.Append(ml.Regression.Trainers.FastTree(labelColumnName: "Age", featureColumnName: outputColumnName, numTrees: 1, numLeaves: 2, minDatapointsInLeaves: 1));
32+
.Append(ml.Regression.Trainers.FastTree(labelColumnName: "Age", featureColumnName: outputColumnName, numberOfTrees: 1, numberOfLeaves: 2, minimumExampleCountPerLeaf: 1));
3333

3434
var model = pipeline.Fit(trainData);
3535

docs/samples/Microsoft.ML.Samples/Dynamic/GeneralizedAdditiveModels.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void Example()
2828
.ToArray();
2929
var pipeline = mlContext.Transforms.Concatenate("Features", featureNames)
3030
.Append(mlContext.Regression.Trainers.GeneralizedAdditiveModels(
31-
labelColumnName: labelName, featureColumnName: "Features", maxBins: 16));
31+
labelColumnName: labelName, featureColumnName: "Features", maxBinCountPerFeature: 16));
3232
var fitPipeline = pipeline.Fit(data);
3333

3434
// Extract the model from the pipeline
@@ -37,7 +37,7 @@ public static void Example()
3737
// Now investigate the properties of the Generalized Additive Model: The intercept and shape functions.
3838

3939
// The intercept for the GAM models represent the average prediction for the training data
40-
var intercept = gamModel.Intercept;
40+
var intercept = gamModel.Bias;
4141
// Expected output: Average predicted cost: 22.53
4242
Console.WriteLine($"Average predicted cost: {intercept:0.00}");
4343

@@ -93,7 +93,7 @@ public static void Example()
9393
// Distillation." <a href='https://arxiv.org/abs/1710.06169'>arXiv:1710.06169</a>."
9494
Console.WriteLine();
9595
Console.WriteLine("Student-Teacher Ratio");
96-
for (int i = 0; i < teacherRatioBinUpperBounds.Length; i++)
96+
for (int i = 0; i < teacherRatioBinUpperBounds.Count; i++)
9797
{
9898
Console.WriteLine($"x < {teacherRatioBinUpperBounds[i]:0.00} => {teacherRatioBinEffects[i]:0.000}");
9999
}

src/Microsoft.ML.FastTree/BoostingFastTree.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private protected override int GetBestIteration(IChannel ch)
164164
private protected double BsrMaxTreeOutput()
165165
{
166166
if (FastTreeTrainerOptions.BestStepRankingRegressionTrees)
167-
return FastTreeTrainerOptions.MaxTreeOutput;
167+
return FastTreeTrainerOptions.MaximumTreeOutput;
168168
else
169169
return -1;
170170
}

src/Microsoft.ML.FastTree/FastTreeArguments.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ internal static class Defaults
146146
{
147147
public const int NumberOfTrees = 100;
148148
public const int NumberOfLeaves = 20;
149-
public const int MinExampleCountInLeaves = 10;
149+
public const int MinimumExampleCountPerLeaf = 10;
150150
public const double LearningRate = 0.2;
151151
}
152152

@@ -320,7 +320,7 @@ public abstract class TreeOptions : LearnerInputBaseWithGroupId
320320
[Argument(ArgumentType.LastOccurenceWins, HelpText = "The minimal number of documents allowed in a leaf of a regression tree, out of the subsampled data", ShortName = "mil,MinDocumentsInLeafs", SortOrder = 3)]
321321
[TGUI(Description = "Minimum number of training instances required to form a leaf", SuggestedSweeps = "1,10,50")]
322322
[TlcModule.SweepableDiscreteParamAttribute("MinDocumentsInLeafs", new object[] { 1, 10, 50 })]
323-
public int MinExampleCountPerLeaf = Defaults.MinExampleCountInLeaves;
323+
public int MinExampleCountPerLeaf = Defaults.MinimumExampleCountPerLeaf;
324324

325325
/// <summary>
326326
/// Total number of decision trees to create in the ensemble.
@@ -463,13 +463,13 @@ public abstract class BoostedTreeOptions : TreeOptions
463463
/// Number of post-bracket line search steps.
464464
/// </summary>
465465
[Argument(ArgumentType.LastOccurenceWins, HelpText = "Number of post-bracket line search steps", ShortName = "lssteps,NumPostBracketSteps")]
466-
public int MaxNumberOfLinearSearchSteps;
466+
public int MaximumNumberOfLineSearchSteps;
467467

468468
/// <summary>
469469
/// Minimum line search step size.
470470
/// </summary>
471-
[Argument(ArgumentType.LastOccurenceWins, HelpText = "Minimum line search step size", ShortName = "minstep")]
472-
public Double MinStepSize;
471+
[Argument(ArgumentType.LastOccurenceWins, HelpText = "Minimum line search step size", ShortName = "minstep,MinStepSize")]
472+
public Double MinimumStepSize;
473473

474474
public enum OptimizationAlgorithmType { GradientDescent, AcceleratedGradientDescent, ConjugateGradientDescent };
475475

@@ -510,7 +510,7 @@ public enum OptimizationAlgorithmType { GradientDescent, AcceleratedGradientDesc
510510
/// </summary>
511511
[Argument(ArgumentType.AtMostOnce, HelpText = "The tolerance threshold for pruning", ShortName = "prth")]
512512
[TGUI(Description = "Pruning threshold")]
513-
public Double PruningThreshold = 0.004;
513+
public double PruningThreshold = 0.004;
514514

515515
/// <summary>
516516
/// The moving window size for pruning.
@@ -525,7 +525,7 @@ public enum OptimizationAlgorithmType { GradientDescent, AcceleratedGradientDesc
525525
[Argument(ArgumentType.LastOccurenceWins, HelpText = "The learning rate", ShortName = "lr,LearningRates", SortOrder = 4)]
526526
[TGUI(Label = "Learning Rate", SuggestedSweeps = "0.025-0.4;log")]
527527
[TlcModule.SweepableFloatParamAttribute("LearningRates", 0.025f, 0.4f, isLogScale: true)]
528-
public Double LearningRate = Defaults.LearningRate;
528+
public double LearningRate = Defaults.LearningRate;
529529

530530
/// <summary>
531531
/// Shrinkage.
@@ -559,7 +559,7 @@ public enum OptimizationAlgorithmType { GradientDescent, AcceleratedGradientDesc
559559
/// Upper bound on absolute value of single tree output.
560560
/// </summary>
561561
[Argument(ArgumentType.AtMostOnce, HelpText = "Upper bound on absolute value of single tree output", ShortName = "mo")]
562-
public Double MaxTreeOutput = 100;
562+
public Double MaximumTreeOutput = 100;
563563

564564
/// <summary>
565565
/// Training starts from random ordering (determined by /r1).
@@ -630,14 +630,14 @@ internal override void Check(IExceptionContext ectx)
630630
{
631631
base.Check(ectx);
632632

633-
ectx.CheckUserArg(0 <= MaxTreeOutput, nameof(MaxTreeOutput), "Must be non-negative.");
633+
ectx.CheckUserArg(0 <= MaximumTreeOutput, nameof(MaximumTreeOutput), "Must be non-negative.");
634634
ectx.CheckUserArg(0 <= PruningThreshold, nameof(PruningThreshold), "Must be non-negative.");
635635
ectx.CheckUserArg(0 < PruningWindowSize, nameof(PruningWindowSize), "Must be positive.");
636636
ectx.CheckUserArg(0 < Shrinkage, nameof(Shrinkage), "Must be positive.");
637637
ectx.CheckUserArg(0 <= DropoutRate && DropoutRate <= 1, nameof(DropoutRate), "Must be between 0 and 1.");
638638
ectx.CheckUserArg(0 < GetDerivativesSampleRate, nameof(GetDerivativesSampleRate), "Must be positive.");
639-
ectx.CheckUserArg(0 <= MaxNumberOfLinearSearchSteps, nameof(MaxNumberOfLinearSearchSteps), "Must be non-negative.");
640-
ectx.CheckUserArg(0 <= MinStepSize, nameof(MinStepSize), "Must be non-negative.");
639+
ectx.CheckUserArg(0 <= MaximumNumberOfLineSearchSteps, nameof(MaximumNumberOfLineSearchSteps), "Must be non-negative.");
640+
ectx.CheckUserArg(0 <= MinimumStepSize, nameof(MinimumStepSize), "Must be non-negative.");
641641
}
642642
}
643643
}

src/Microsoft.ML.FastTree/FastTreeClassification.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.ML.Calibrators;
1111
using Microsoft.ML.Data;
1212
using Microsoft.ML.EntryPoints;
13-
using Microsoft.ML.Internal.Internallearn;
1413
using Microsoft.ML.Model;
1514
using Microsoft.ML.Trainers.FastTree;
1615

@@ -132,7 +131,7 @@ internal FastTreeBinaryClassificationTrainer(IHostEnvironment env,
132131
string weightColumn = null,
133132
int numLeaves = Defaults.NumberOfLeaves,
134133
int numTrees = Defaults.NumberOfTrees,
135-
int minDatapointsInLeaves = Defaults.MinExampleCountInLeaves,
134+
int minDatapointsInLeaves = Defaults.MinimumExampleCountPerLeaf,
136135
double learningRate = Defaults.LearningRate)
137136
: base(env, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, null, numLeaves, numTrees, minDatapointsInLeaves, learningRate)
138137
{
@@ -195,7 +194,7 @@ private protected override ObjectiveFunctionBase ConstructObjFunc(IChannel ch)
195194
FastTreeTrainerOptions.Shrinkage,
196195
_sigmoidParameter,
197196
FastTreeTrainerOptions.UnbalancedSets,
198-
FastTreeTrainerOptions.MaxTreeOutput,
197+
FastTreeTrainerOptions.MaximumTreeOutput,
199198
FastTreeTrainerOptions.GetDerivativesSampleRate,
200199
FastTreeTrainerOptions.BestStepRankingRegressionTrees,
201200
FastTreeTrainerOptions.RandomSeed,
@@ -209,7 +208,7 @@ private protected override OptimizationAlgorithm ConstructOptimizationAlgorithm(
209208
{
210209
var lossCalculator = new BinaryClassificationTest(optimizationAlgorithm.TrainingScores, _trainSetLabels, _sigmoidParameter);
211210
// REVIEW: we should makeloss indices an enum in BinaryClassificationTest
212-
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(lossCalculator, FastTreeTrainerOptions.UnbalancedSets ? 3 /*Unbalanced sets loss*/ : 1 /*normal loss*/, FastTreeTrainerOptions.MaxNumberOfLinearSearchSteps, FastTreeTrainerOptions.MinStepSize);
211+
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(lossCalculator, FastTreeTrainerOptions.UnbalancedSets ? 3 /*Unbalanced sets loss*/ : 1 /*normal loss*/, FastTreeTrainerOptions.MaximumNumberOfLineSearchSteps, FastTreeTrainerOptions.MinimumStepSize);
213212
}
214213
return optimizationAlgorithm;
215214
}

src/Microsoft.ML.FastTree/FastTreeRanking.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.ML;
1313
using Microsoft.ML.Data;
1414
using Microsoft.ML.EntryPoints;
15-
using Microsoft.ML.Internal.Internallearn;
1615
using Microsoft.ML.Internal.Utilities;
1716
using Microsoft.ML.Model;
1817
using Microsoft.ML.Trainers.FastTree;
@@ -76,7 +75,7 @@ internal FastTreeRankingTrainer(IHostEnvironment env,
7675
string weightColumn = null,
7776
int numLeaves = Defaults.NumberOfLeaves,
7877
int numTrees = Defaults.NumberOfTrees,
79-
int minDatapointsInLeaves = Defaults.MinExampleCountInLeaves,
78+
int minDatapointsInLeaves = Defaults.MinimumExampleCountPerLeaf,
8079
double learningRate = Defaults.LearningRate)
8180
: base(env, TrainerUtils.MakeR4ScalarColumn(labelColumn), featureColumn, weightColumn, groupIdColumn, numLeaves, numTrees, minDatapointsInLeaves, learningRate)
8281
{
@@ -193,7 +192,7 @@ private protected override OptimizationAlgorithm ConstructOptimizationAlgorithm(
193192
if (FastTreeTrainerOptions.UseLineSearch)
194193
{
195194
_specialTrainSetTest = new FastNdcgTest(optimizationAlgorithm.TrainingScores, TrainSet.Ratings, FastTreeTrainerOptions.SortingAlgorithm, FastTreeTrainerOptions.EarlyStoppingMetrics);
196-
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(_specialTrainSetTest, 0, FastTreeTrainerOptions.MaxNumberOfLinearSearchSteps, FastTreeTrainerOptions.MinStepSize);
195+
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(_specialTrainSetTest, 0, FastTreeTrainerOptions.MaximumNumberOfLineSearchSteps, FastTreeTrainerOptions.MinimumStepSize);
197196
}
198197
return optimizationAlgorithm;
199198
}
@@ -554,7 +553,7 @@ public LambdaRankObjectiveFunction(Dataset trainset, short[] labels, Options opt
554553
: base(trainset,
555554
options.LearningRate,
556555
options.Shrinkage,
557-
options.MaxTreeOutput,
556+
options.MaximumTreeOutput,
558557
options.GetDerivativesSampleRate,
559558
options.BestStepRankingRegressionTrees,
560559
options.RandomSeed)

src/Microsoft.ML.FastTree/FastTreeRegression.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.ML;
99
using Microsoft.ML.Data;
1010
using Microsoft.ML.EntryPoints;
11-
using Microsoft.ML.Internal.Internallearn;
1211
using Microsoft.ML.Model;
1312
using Microsoft.ML.Trainers.FastTree;
1413

@@ -65,7 +64,7 @@ internal FastTreeRegressionTrainer(IHostEnvironment env,
6564
string weightColumn = null,
6665
int numLeaves = Defaults.NumberOfLeaves,
6766
int numTrees = Defaults.NumberOfTrees,
68-
int minDatapointsInLeaves = Defaults.MinExampleCountInLeaves,
67+
int minDatapointsInLeaves = Defaults.MinimumExampleCountPerLeaf,
6968
double learningRate = Defaults.LearningRate)
7069
: base(env, TrainerUtils.MakeR4ScalarColumn(labelColumn), featureColumn, weightColumn, null, numLeaves, numTrees, minDatapointsInLeaves, learningRate)
7170
{
@@ -127,7 +126,7 @@ private protected override OptimizationAlgorithm ConstructOptimizationAlgorithm(
127126
{
128127
var lossCalculator = new RegressionTest(optimizationAlgorithm.TrainingScores);
129128
// REVIEW: We should make loss indices an enum in BinaryClassificationTest.
130-
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(lossCalculator, 1 /*L2 error*/, FastTreeTrainerOptions.MaxNumberOfLinearSearchSteps, FastTreeTrainerOptions.MinStepSize);
129+
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(lossCalculator, 1 /*L2 error*/, FastTreeTrainerOptions.MaximumNumberOfLineSearchSteps, FastTreeTrainerOptions.MinimumStepSize);
131130
}
132131

133132
return optimizationAlgorithm;
@@ -390,12 +389,12 @@ internal sealed class ObjectiveImpl : ObjectiveFunctionBase, IStepSearch
390389
public ObjectiveImpl(Dataset trainData, RegressionGamTrainer.Options options) :
391390
base(
392391
trainData,
393-
options.LearningRates,
392+
options.LearningRate,
394393
0,
395-
options.MaxOutput,
394+
options.MaximumTreeOutput,
396395
options.GetDerivativesSampleRate,
397396
false,
398-
options.RngSeed)
397+
options.Seed)
399398
{
400399
_labels = GetDatasetRegressionLabels(trainData);
401400
}
@@ -405,7 +404,7 @@ public ObjectiveImpl(Dataset trainData, Options options)
405404
trainData,
406405
options.LearningRate,
407406
options.Shrinkage,
408-
options.MaxTreeOutput,
407+
options.MaximumTreeOutput,
409408
options.GetDerivativesSampleRate,
410409
options.BestStepRankingRegressionTrees,
411410
options.RandomSeed)

src/Microsoft.ML.FastTree/FastTreeTweedie.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.ML;
1010
using Microsoft.ML.Data;
1111
using Microsoft.ML.EntryPoints;
12-
using Microsoft.ML.Internal.Internallearn;
1312
using Microsoft.ML.Internal.Utilities;
1413
using Microsoft.ML.Model;
1514
using Microsoft.ML.Trainers.FastTree;
@@ -63,7 +62,7 @@ internal FastTreeTweedieTrainer(IHostEnvironment env,
6362
string weightColumn = null,
6463
int numLeaves = Defaults.NumberOfLeaves,
6564
int numTrees = Defaults.NumberOfTrees,
66-
int minDatapointsInLeaves = Defaults.MinExampleCountInLeaves,
65+
int minDatapointsInLeaves = Defaults.MinimumExampleCountPerLeaf,
6766
double learningRate = Defaults.LearningRate)
6867
: base(env, TrainerUtils.MakeR4ScalarColumn(labelColumn), featureColumn, weightColumn, null, numLeaves, numTrees, minDatapointsInLeaves, learningRate)
6968
{
@@ -134,7 +133,7 @@ private protected override OptimizationAlgorithm ConstructOptimizationAlgorithm(
134133
var lossCalculator = new RegressionTest(optimizationAlgorithm.TrainingScores);
135134
// REVIEW: We should make loss indices an enum in BinaryClassificationTest.
136135
// REVIEW: Nope, subcomponent.
137-
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(lossCalculator, 1 /*L2 error*/, FastTreeTrainerOptions.MaxNumberOfLinearSearchSteps, FastTreeTrainerOptions.MinStepSize);
136+
optimizationAlgorithm.AdjustTreeOutputsOverride = new LineSearch(lossCalculator, 1 /*L2 error*/, FastTreeTrainerOptions.MaximumNumberOfLineSearchSteps, FastTreeTrainerOptions.MinimumStepSize);
138137
}
139138

140139
return optimizationAlgorithm;
@@ -343,7 +342,7 @@ public ObjectiveImpl(Dataset trainData, Options options)
343342
trainData,
344343
options.LearningRate,
345344
options.Shrinkage,
346-
options.MaxTreeOutput,
345+
options.MaximumTreeOutput,
347346
options.GetDerivativesSampleRate,
348347
options.BestStepRankingRegressionTrees,
349348
options.RandomSeed)
@@ -361,7 +360,7 @@ public ObjectiveImpl(Dataset trainData, Options options)
361360

362361
_index1 = 1 - options.Index;
363362
_index2 = 2 - options.Index;
364-
_maxClamp = Math.Abs(options.MaxTreeOutput);
363+
_maxClamp = Math.Abs(options.MaximumTreeOutput);
365364
}
366365

367366
public void AdjustTreeOutputs(IChannel ch, InternalRegressionTree tree, DocumentPartitioning partitioning, ScoreTracker trainingScores)

src/Microsoft.ML.FastTree/GamClassification.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ internal BinaryClassificationGamTrainer(IHostEnvironment env,
6969
string labelColumn = DefaultColumnNames.Label,
7070
string featureColumn = DefaultColumnNames.Features,
7171
string weightColumn = null,
72-
int numIterations = GamDefaults.NumIterations,
73-
double learningRate = GamDefaults.LearningRates,
74-
int maxBins = GamDefaults.MaxBins)
72+
int numIterations = GamDefaults.NumberOfIterations,
73+
double learningRate = GamDefaults.LearningRate,
74+
int maxBins = GamDefaults.MaximumBinCountPerFeature)
7575
: base(env, LoadNameValue, TrainerUtils.MakeBoolScalarLabel(labelColumn), featureColumn, weightColumn, numIterations, learningRate, maxBins)
7676
{
7777
_sigmoidParameter = 1;
@@ -115,14 +115,14 @@ private protected override ObjectiveFunctionBase CreateObjectiveFunction()
115115
return new FastTreeBinaryClassificationTrainer.ObjectiveImpl(
116116
TrainSet,
117117
ConvertTargetsToBool(TrainSet.Targets),
118-
GamTrainerOptions.LearningRates,
118+
GamTrainerOptions.LearningRate,
119119
0,
120120
_sigmoidParameter,
121121
GamTrainerOptions.UnbalancedSets,
122-
GamTrainerOptions.MaxOutput,
122+
GamTrainerOptions.MaximumTreeOutput,
123123
GamTrainerOptions.GetDerivativesSampleRate,
124124
false,
125-
GamTrainerOptions.RngSeed,
125+
GamTrainerOptions.Seed,
126126
ParallelTraining
127127
);
128128
}

0 commit comments

Comments
 (0)