-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Part 3] Added convenience constructors for set of transforms. #520
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
Changes from 1 commit
d9c4a29
6cd77eb
75a8b6d
d72a4ac
3dd9847
730fe93
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 |
---|---|---|
|
@@ -33,6 +33,13 @@ public static class MutualInformationFeatureSelectionTransform | |
public const string UserName = "Mutual Information Feature Selection Transform"; | ||
public const string ShortName = "MIFeatureSelection"; | ||
|
||
private static class Defaults | ||
{ | ||
public const string LabelColumn = DefaultColumnNames.Label; | ||
public const int SlotsInOutput = 1000; | ||
public const int NumBins = 256; | ||
} | ||
|
||
public sealed class Arguments : TransformInputBase | ||
{ | ||
[Argument(ArgumentType.Multiple | ArgumentType.Required, HelpText = "Columns to use for feature selection", ShortName = "col", | ||
|
@@ -41,19 +48,45 @@ public sealed class Arguments : TransformInputBase | |
|
||
[Argument(ArgumentType.LastOccurenceWins, HelpText = "Column to use for labels", ShortName = "lab", | ||
SortOrder = 4, Purpose = SpecialPurpose.ColumnName)] | ||
public string LabelColumn = DefaultColumnNames.Label; | ||
public string LabelColumn = Defaults.LabelColumn; | ||
|
||
[Argument(ArgumentType.AtMostOnce, HelpText = "The maximum number of slots to preserve in output", ShortName = "topk,numSlotsToKeep", | ||
SortOrder = 1)] | ||
public int SlotsInOutput = 1000; | ||
public int SlotsInOutput = Defaults.SlotsInOutput; | ||
|
||
[Argument(ArgumentType.AtMostOnce, HelpText = "Max number of bins for R4/R8 columns, power of 2 recommended", | ||
ShortName = "bins")] | ||
public int NumBins = 256; | ||
public int NumBins = Defaults.NumBins; | ||
} | ||
|
||
internal static string RegistrationName = "MutualInformationFeatureSelectionTransform"; | ||
|
||
/// <summary> | ||
/// A helper method to create <see cref="MutualInformationFeatureSelectionTransform"/> for public facing API. | ||
|
||
/// </summary> | ||
/// <param name="env">Host Environment.</param> | ||
/// <param name="input">Input <see cref="IDataView"/>. This is the output from previous transform or loader.</param> | ||
/// <param name="labelColumn">Column to use for labels.</param> | ||
/// <param name="slotsInOutput">The maximum number of slots to preserve in output.</param> | ||
/// <param name="numBins">Max number of bins for R4/R8 columns, power of 2 recommended.</param> | ||
/// <param name="columns">Columns to use for feature selection.</param> | ||
public static IDataTransform Create(IHostEnvironment env, | ||
IDataView input, | ||
string labelColumn = Defaults.LabelColumn, | ||
int slotsInOutput = Defaults.SlotsInOutput, | ||
int numBins = Defaults.NumBins, | ||
params string[] columns) | ||
{ | ||
var args = new Arguments() | ||
{ | ||
Column = columns, | ||
LabelColumn = labelColumn, | ||
SlotsInOutput = slotsInOutput, | ||
NumBins = numBins | ||
}; | ||
return Create(env, args, input); | ||
} | ||
|
||
/// <summary> | ||
/// Create method corresponding to SignatureDataTransform. | ||
/// </summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,15 @@ namespace Microsoft.ML.Runtime.Data | |
/// </summary> | ||
public sealed class ProduceIdTransform : RowToRowTransformBase | ||
{ | ||
private static class Defaults | ||
{ | ||
public const string Column = "Id"; | ||
} | ||
|
||
|
||
public sealed class Arguments | ||
{ | ||
[Argument(ArgumentType.AtMostOnce, HelpText = "Name of the column to produce", ShortName = "col", SortOrder = 1)] | ||
public string Column = "Id"; | ||
public string Column = Defaults.Column; | ||
} | ||
|
||
private sealed class Bindings : ColumnBindingsBase | ||
|
@@ -93,6 +98,17 @@ private static VersionInfo GetVersionInfo() | |
|
||
public override bool CanShuffle { get { return Source.CanShuffle; } } | ||
|
||
/// <summary> | ||
/// Convenience constructor for public facing API. | ||
/// </summary> | ||
/// <param name="env">Host Environment.</param> | ||
/// <param name="input">Input <see cref="IDataView"/>. This is the output from previous transform or loader.</param> | ||
/// <param name="column">Name of the column to produce.</param> | ||
public ProduceIdTransform(IHostEnvironment env, IDataView input, string column = Defaults.Column) | ||
: this(env, new Arguments() { Column = column }, input) | ||
{ | ||
} | ||
|
||
public ProduceIdTransform(IHostEnvironment env, Arguments args, IDataView input) | ||
: base(env, LoaderSignature, input) | ||
{ | ||
|
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.
Considering the cases I'm aware of where it is used, I have to think that a single string would be preferable for the convenience constructor. #Closed