-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Tree estimators #855
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
Tree estimators #855
Changes from 3 commits
cbd84ab
0f68992
c76285c
13a187e
8e76ef1
e5f8925
f2410a6
574b9d2
4b3da66
63e63d5
0cccda5
5073a90
edc39d5
66eaf76
2d8b525
df5449a
e770ddc
e8fb048
7ce1bd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ | |
| using Microsoft.ML.Runtime.Training; | ||
| using Microsoft.ML.Runtime.TreePredictor; | ||
| using Newtonsoft.Json.Linq; | ||
| using Microsoft.ML.Core.Data; | ||
| using Microsoft.ML.Runtime.EntryPoints; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably just missing something obvious, but why does this now depend on entry-points namespace? Also sorting. #Resolved
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // All of these reviews apply in general to fast tree and random forest implementations. | ||
| //REVIEW: Decouple train method in Application.cs to have boosting and random forest logic seperate. | ||
|
|
@@ -43,10 +45,11 @@ internal static class FastTreeShared | |
| public static readonly object TrainLock = new object(); | ||
| } | ||
|
|
||
| public abstract class FastTreeTrainerBase<TArgs, TPredictor> : | ||
| TrainerBase<TPredictor> | ||
| public abstract class FastTreeTrainerBase<TArgs, TTransformer, TModel> : | ||
| TrainerEstimatorBase<TTransformer, TModel> | ||
| where TTransformer: IPredictionTransformer<TModel> | ||
| where TArgs : TreeArgs, new() | ||
| where TPredictor : IPredictorProducing<Float> | ||
| where TModel : IPredictorProducing<Float> | ||
| { | ||
| protected readonly TArgs Args; | ||
| protected readonly bool AllowGC; | ||
|
|
@@ -87,8 +90,8 @@ public abstract class FastTreeTrainerBase<TArgs, TPredictor> : | |
|
|
||
| private protected virtual bool NeedCalibration => false; | ||
|
|
||
| private protected FastTreeTrainerBase(IHostEnvironment env, TArgs args) | ||
| : base(env, RegisterName) | ||
| private protected FastTreeTrainerBase(IHostEnvironment env, TArgs args, SchemaShape.Column label) | ||
| : base(Contracts.CheckRef(env, nameof(env)).Register(RegisterName), MakeFeatureColumn(args.FeatureColumn), label, MakeWeightColumn(args.WeightColumn)) | ||
| { | ||
| Host.CheckValue(args, nameof(args)); | ||
| Args = args; | ||
|
|
@@ -133,6 +136,18 @@ protected virtual Float GetMaxLabel() | |
| return Float.PositiveInfinity; | ||
| } | ||
|
|
||
| private static SchemaShape.Column MakeWeightColumn(Optional<string> weightColumn) | ||
| { | ||
| if (weightColumn == null || !weightColumn.IsExplicit) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this is not entirely correct either. It won't create the column when the user doesn't specify the weight colum, because it already had the name weight in the data. @tfinley@gmail.com @Zruty0 can we move from the Optional to just string for the weight, name, group ID and enforce the user typing in the names? is there another way around it, now that we need to know the information before seeing the data? #Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return null; | ||
| return new SchemaShape.Column(weightColumn, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false); | ||
| } | ||
|
|
||
| private static SchemaShape.Column MakeFeatureColumn(string featureColumn) | ||
| { | ||
| return new SchemaShape.Column(featureColumn, SchemaShape.Column.VectorKind.Vector, NumberType.R4, false); | ||
| } | ||
|
|
||
| protected void ConvertData(RoleMappedData trainData) | ||
| { | ||
| trainData.Schema.Schema.TryGetColumnIndex(DefaultColumnNames.Features, out int featureIndex); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| using Microsoft.ML.Runtime.Internal.Utilities; | ||
| using Microsoft.ML.Runtime.Model; | ||
| using Microsoft.ML.Runtime.Internal.Internallearn; | ||
| using Microsoft.ML.Core.Data; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sort #Resolved |
||
|
|
||
| // REVIEW: Do we really need all these names? | ||
| [assembly: LoadableClass(FastTreeRankingTrainer.Summary, typeof(FastTreeRankingTrainer), typeof(FastTreeRankingTrainer.Arguments), | ||
|
|
@@ -39,8 +40,9 @@ | |
| namespace Microsoft.ML.Runtime.FastTree | ||
| { | ||
| /// <include file='doc.xml' path='doc/members/member[@name="FastTree"]/*' /> | ||
| public sealed partial class FastTreeRankingTrainer : BoostingFastTreeTrainerBase<FastTreeRankingTrainer.Arguments, FastTreeRankingPredictor>, | ||
| IHasLabelGains | ||
| public sealed partial class FastTreeRankingTrainer | ||
| : BoostingFastTreeTrainerBase<FastTreeRankingTrainer.Arguments, RankingPredictionTransformer<FastTreeRankingPredictor>, FastTreeRankingPredictor>, | ||
| IHasLabelGains | ||
| { | ||
| public const string LoadNameValue = "FastTreeRanking"; | ||
| internal const string UserNameValue = "FastTree (Boosted Trees) Ranking"; | ||
|
|
@@ -53,17 +55,25 @@ public sealed partial class FastTreeRankingTrainer : BoostingFastTreeTrainerBase | |
|
|
||
| public override PredictionKind PredictionKind => PredictionKind.Ranking; | ||
|
|
||
| protected override SchemaShape.Column[] OutputColumns { get; } | ||
|
|
||
| public FastTreeRankingTrainer(IHostEnvironment env, Arguments args) | ||
| : base(env, args) | ||
| : base(env, args, MakeLabelColumn(args.LabelColumn)) | ||
| { | ||
| OutputColumns = new[] | ||
| { | ||
| new SchemaShape.Column(DefaultColumnNames.Score, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false), | ||
| new SchemaShape.Column(DefaultColumnNames.Probability, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false), | ||
| new SchemaShape.Column(DefaultColumnNames.PredictedLabel, SchemaShape.Column.VectorKind.Scalar, BoolType.Instance, false) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double-check this is correct |
||
| }; | ||
| } | ||
|
|
||
| protected override float GetMaxLabel() | ||
| { | ||
| return GetLabelGains().Length - 1; | ||
| } | ||
|
|
||
| public override FastTreeRankingPredictor Train(TrainContext context) | ||
| protected override FastTreeRankingPredictor TrainModelCore(TrainContext context) | ||
| { | ||
| Host.CheckValue(context, nameof(context)); | ||
| var trainData = context.TrainingSet; | ||
|
|
@@ -125,6 +135,11 @@ protected override void CheckArgs(IChannel ch) | |
| base.CheckArgs(ch); | ||
| } | ||
|
|
||
| private static SchemaShape.Column MakeLabelColumn(string labelColumn) | ||
| { | ||
| return new SchemaShape.Column(labelColumn, SchemaShape.Column.VectorKind.Scalar, NumberType.R4, false); | ||
| } | ||
|
|
||
| protected override void Initialize(IChannel ch) | ||
| { | ||
| base.Initialize(ch); | ||
|
|
@@ -405,6 +420,9 @@ protected override string GetTestGraphHeader() | |
| return headerBuilder.ToString(); | ||
| } | ||
|
|
||
| protected override RankingPredictionTransformer<FastTreeRankingPredictor> MakeTransformer(FastTreeRankingPredictor model, ISchema trainSchema) | ||
| => new RankingPredictionTransformer<FastTreeRankingPredictor>(Host, model, trainSchema, FeatureColumn.Name); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
should add the GroupID to the base constructor #Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| public sealed class LambdaRankObjectiveFunction : ObjectiveFunctionBase, IStepSearch | ||
| { | ||
| private readonly short[] _labels; | ||
|
|
||
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.
Is the reason why we have two types that are identical in practically everything but name, so we can identify ranking estimators vs. regression estimators in a statically typed way?
Uh oh!
There was an error while loading. Please reload this page.
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.
I think this transformer should also expose the group ID column name, at least that would be my belief
In reply to: 218214277 [](ancestors = 218214277)
Uh oh!
There was an error while loading. Please reload this page.
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.
Actually thought about this, like labels group ids are only needed for training, right? So for prediction I don't think they should be.
In reply to: 218216192 [](ancestors = 218216192,218214277)
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.
So keep it, or make the Regression one Generic and use it for both?
In reply to: 218216839 [](ancestors = 218216839,218216192,218214277)