-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Modify API for advanced settings (several learners) #2163
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
Conversation
@abgoswam What if user wants to set certain advance settings for the trainer. How is he going to do it now? Previously, AdvanceSettings Func was the way to do it. #Resolved |
My Bad. you have renamed it to Options. Nevermind. Thanks #Resolved |
env => new LinearSvmTrainer(env)) | ||
env => { | ||
var mlContext = new MLContext(); | ||
return mlContext.BinaryClassification.Trainers.LinearSupportVectorMachines(); |
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 don't think it is a good idea to create another context/environment.
Just use the constructor, for internal code.
Add the [BestFriend] annotation to LinearSVM, if it canot be accessed from here. #Closed
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.
thanks. for the tip about using the [BestFriend] attribute
In reply to: 248542758 [](ancestors = 248542758)
env => new MulticlassLogisticRegression(env, LabelColumn, FeatureColumn)) | ||
env => { | ||
var mlContext = new MLContext(); | ||
return mlContext.MulticlassClassification.Trainers.LogisticRegression(LabelColumn, FeatureColumn); |
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.
here too. #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.
env => { | ||
var mlContext = new MLContext(); | ||
return mlContext.Regression.Trainers.OnlineGradientDescent(); | ||
}) |
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.
one more #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.
} | ||
|
||
/// <summary> | ||
/// Predict a target using a linear binary classification model trained with the AveragedPerceptron trainer, and a custom loss. |
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.
r, and a custom loss [](start = 114, length = 20)
maybe doesn't make sense to call out the loss here. #Closed
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.
} | ||
|
||
/// <summary> | ||
/// Predict a target using a linear binary classification model trained with the AveragedPerceptron trainer, and a custom loss. |
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.
AveragedPerceptron [](start = 89, length = 18)
on type references.
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 don't think we need to add a type reference here. Do we ?
My sense is we are using it to refer to the Averaged Perceptron algo, and not to a specific type within ML.NET
In reply to: 248543067 [](ancestors = 248543067)
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.
it says AveragePerception trainer. I think it would be good to point to the actual trainer class, so they can read more about the algo. Leaving it like this will cause the users to.. web search.
In reply to: 248786650 [](ancestors = 248786650,248543067)
/// Predict a target using a linear binary classification model trained with the AveragedPerceptron trainer, and a custom loss. | ||
/// </summary> | ||
/// <param name="ctx">The binary classification context trainer object.</param> | ||
/// <param name="options">Advanced arguments to the algorithm.</param> |
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.
arguments [](start = 43, length = 9)
options, here and in the other ones.
I didn't do it in my PR, but thinking now that it might make sense to to the Options class, so users can see the options. #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.
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.
You have it in your list of things to do :)
Up to you, as long as it gets done.
In reply to: 248787187 [](ancestors = 248787187,248543101)
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.
/// Predict a target using a linear regression model trained with the <see cref="OnlineGradientDescentTrainer"/> trainer. | ||
/// </summary> | ||
/// <param name="ctx">The regression context trainer object.</param> | ||
/// <param name="options">Advanced arguments to the algorithm.</param> |
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.
arguments [](start = 43, length = 9)
here #Resolved
/// Predict a target using a linear binary classification model trained with the <see cref="Microsoft.ML.Learners.LogisticRegression"/> trainer. | ||
/// </summary> | ||
/// <param name="ctx">The binary classificaiton context trainer object.</param> | ||
/// <param name="options">Advanced arguments to the algorithm.</param> |
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.
arguments [](start = 43, length = 9)
options #Resolved
{ | ||
Contracts.CheckValue(ctx, nameof(ctx)); | ||
var env = CatalogUtils.GetEnvironment(ctx); | ||
return new PoissonRegression(env, labelColumn, featureColumn, weights, l1Weight, l2Weight, optimizationTolerance, memorySize, enforceNoNegativity, advancedSettings); | ||
return new PoissonRegression(env, labelColumn, featureColumn, weights, l1Weight, l2Weight, optimizationTolerance, memorySize, enforceNoNegativity); |
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.
PoissonRegression [](start = 23, length = 17)
does it make sense to call the other ctor, the new PoissonRegression(env, options); and just delete this ctor on this PR, or you'll tackle it later? #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.
@@ -74,18 +74,16 @@ public sealed class Arguments : ArgumentsBase | |||
/// <param name="l2Weight">Weight of L2 regularizer term.</param> | |||
/// <param name="memorySize">Memory size for <see cref="LogisticRegression"/>. Low=faster, less accurate.</param> | |||
/// <param name="optimizationTolerance">Threshold for optimizer convergence.</param> | |||
/// <param name="advancedSettings">A delegate to apply all the advanced arguments to the algorithm.</param> | |||
public LogisticRegression(IHostEnvironment env, | |||
internal LogisticRegression(IHostEnvironment env, | |||
string labelColumn = DefaultColumnNames.Label, | |||
string featureColumn = DefaultColumnNames.Features, | |||
string weights = null, |
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'd just delete it.. #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.
I do see it being passed to base constructor LbfgsTrainerBase
where its used to initialize WeightsColumn
Thoughts ?
In reply to: 248543741 [](ancestors = 248543741)
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.
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.
MulticlassPredictionTransformer<MulticlassLogisticRegressionModelParameters>, MulticlassLogisticRegressionModelParameters> | ||
{ | ||
public const string LoadNameValue = "MultiClassLogisticRegression"; | ||
internal const string UserNameValue = "Multi-class Logistic Regression"; | ||
internal const string ShortName = "mlr"; | ||
|
||
public sealed class Arguments : ArgumentsBase | ||
public sealed class Options : ArgumentsBase | ||
{ | ||
[Argument(ArgumentType.AtMostOnce, HelpText = "Show statistics of training examples.", ShortName = "stat", SortOrder = 50)] | ||
public bool ShowTrainingStats = false; |
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.
ShowTrainingStats [](start = 24, length = 17)
xml #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.
|
||
public sealed class Arguments : AveragedLinearArguments | ||
public sealed class Options : AveragedLinearArguments | ||
{ | ||
[Argument(ArgumentType.Multiple, HelpText = "Loss Function", ShortName = "loss", SortOrder = 50)] | ||
public ISupportClassificationLossFactory LossFunction = new HingeLoss.Arguments(); |
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.
ISupportClassificationLossFactory [](start = 19, length = 33)
xml #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.
@@ -103,18 +103,16 @@ internal AveragedPerceptronTrainer(IHostEnvironment env, Arguments args) | |||
/// <param name="decreaseLearningRate">Wheather to decrease learning rate as iterations progress.</param> | |||
/// <param name="l2RegularizerWeight">L2 Regularization Weight.</param> | |||
/// <param name="numIterations">The number of training iteraitons.</param> | |||
/// <param name="advancedSettings">A delegate to supply more advanced arguments to the algorithm.</param> | |||
public AveragedPerceptronTrainer(IHostEnvironment env, | |||
internal AveragedPerceptronTrainer(IHostEnvironment env, | |||
string labelColumn = DefaultColumnNames.Label, | |||
string featureColumn = DefaultColumnNames.Features, | |||
string weights = null, |
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.
delete.. #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.
I do see it being used to initialize InitialWeights
. Thoughts ?
In reply to: 248544047 [](ancestors = 248544047)
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.
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.
{ | ||
options.LabelColumn = labelName; | ||
options.FeatureColumn = featuresName; | ||
options.InitialWeights = weightsName; |
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.
InitialWeights [](start = 28, length = 14)
just checking that this is not an Optional #Closed
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.
yeap . its of type string
in OnlineLinear.cs
public string InitialWeights;
In reply to: 248544431 [](ancestors = 248544431)
@@ -36,16 +36,14 @@ public void OnlineLinearWorkout() | |||
.Append(r => (r.Label, Features: r.Features.Normalize())); | |||
|
|||
var binaryTrainData = binaryPipe.Fit(binaryData).Transform(binaryData).AsDynamic; | |||
var apTrainer = new AveragedPerceptronTrainer(ML, "Label", "Features", lossFunction: new HingeLoss(), advancedSettings: s => |
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.
lossFunction: new HingeLoss() [](start = 83, length = 29)
set this inside Options, so we keep the test the same. #Pending
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.
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.
Towards #1798 .
This PR addresses the following algos
The following changes have been made:
public
extension methods, one for simple arguments and the other for advanced optionsinternal