Skip to content

Commit

Permalink
Rename LabelColumn to LabelColumnName for MutualInformationSelector (d…
Browse files Browse the repository at this point in the history
…otnet#4117)

* Rename labelColumn to labelColumnName

* fix manifest
  • Loading branch information
ganik authored Aug 17, 2019
1 parent 398a978 commit e7a49e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.ML.Transforms/FeatureSelectionCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class FeatureSelectionCatalog
/// </example>
public static MutualInformationFeatureSelectingEstimator SelectFeaturesBasedOnMutualInformation(this TransformsCatalog.FeatureSelectionTransforms catalog,
string outputColumnName, string inputColumnName = null,
string labelColumnName = MutualInfoSelectDefaults.LabelColumn,
string labelColumnName = MutualInfoSelectDefaults.LabelColumnName,
int slotsInOutput = MutualInfoSelectDefaults.SlotsInOutput,
int numberOfBins = MutualInfoSelectDefaults.NumBins)
=> new MutualInformationFeatureSelectingEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, inputColumnName, labelColumnName, slotsInOutput, numberOfBins);
Expand All @@ -58,7 +58,7 @@ public static MutualInformationFeatureSelectingEstimator SelectFeaturesBasedOnMu
/// </example>
public static MutualInformationFeatureSelectingEstimator SelectFeaturesBasedOnMutualInformation(this TransformsCatalog.FeatureSelectionTransforms catalog,
InputOutputColumnPair[] columns,
string labelColumnName = MutualInfoSelectDefaults.LabelColumn,
string labelColumnName = MutualInfoSelectDefaults.LabelColumnName,
int slotsInOutput = MutualInfoSelectDefaults.SlotsInOutput,
int numberOfBins = MutualInfoSelectDefaults.NumBins)
{
Expand Down
30 changes: 15 additions & 15 deletions src/Microsoft.ML.Transforms/MutualInformationFeatureSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public sealed class MutualInformationFeatureSelectingEstimator : IEstimator<ITra
[BestFriend]
internal static class Defaults
{
public const string LabelColumn = DefaultColumnNames.Label;
public const string LabelColumnName = DefaultColumnNames.Label;
public const int SlotsInOutput = 1000;
public const int NumBins = 256;
}
Expand All @@ -92,7 +92,7 @@ internal sealed class Options : TransformInputBase

[Argument(ArgumentType.LastOccurenceWins, HelpText = "Column to use for labels", ShortName = "lab",
SortOrder = 4, Purpose = SpecialPurpose.ColumnName)]
public string LabelColumn = Defaults.LabelColumn;
public string LabelColumnName = Defaults.LabelColumnName;

[Argument(ArgumentType.AtMostOnce, HelpText = "The maximum number of slots to preserve in output", ShortName = "topk,numSlotsToKeep",
SortOrder = 1)]
Expand All @@ -105,13 +105,13 @@ internal sealed class Options : TransformInputBase

private IHost _host;
private readonly (string outputColumnName, string inputColumnName)[] _columns;
private readonly string _labelColumn;
private readonly string _labelColumnName;
private readonly int _slotsInOutput;
private readonly int _numBins;

/// <include file='doc.xml' path='doc/members/member[@name="MutualInformationFeatureSelection"]/*' />
/// <param name="env">The environment to use.</param>
/// <param name="labelColumn">Name of the column to use for labels.</param>
/// <param name="labelColumnName">Name of the column to use for labels.</param>
/// <param name="slotsInOutput">The maximum number of slots to preserve in the output. The number of slots to preserve is taken across all input columns.</param>
/// <param name="numberOfBins">Max number of bins used to approximate mutual information between each input column and the label column. Power of 2 recommended.</param>
/// <param name="columns">Specifies the names of the input columns for the transformation, and their respective output column names.</param>
Expand All @@ -123,7 +123,7 @@ internal sealed class Options : TransformInputBase
/// </format>
/// </example>
internal MutualInformationFeatureSelectingEstimator(IHostEnvironment env,
string labelColumn = Defaults.LabelColumn,
string labelColumnName = Defaults.LabelColumnName,
int slotsInOutput = Defaults.SlotsInOutput,
int numberOfBins = Defaults.NumBins,
params (string outputColumnName, string inputColumnName)[] columns)
Expand All @@ -133,11 +133,11 @@ internal MutualInformationFeatureSelectingEstimator(IHostEnvironment env,

_host.CheckUserArg(Utils.Size(columns) > 0, nameof(columns));
_host.CheckUserArg(slotsInOutput > 0, nameof(slotsInOutput));
_host.CheckNonWhiteSpace(labelColumn, nameof(labelColumn));
_host.CheckNonWhiteSpace(labelColumnName, nameof(labelColumnName));
_host.Check(numberOfBins > 1, "numBins must be greater than 1.");

_columns = columns;
_labelColumn = labelColumn;
_labelColumnName = labelColumnName;
_slotsInOutput = slotsInOutput;
_numBins = numberOfBins;
}
Expand All @@ -146,7 +146,7 @@ internal MutualInformationFeatureSelectingEstimator(IHostEnvironment env,
/// <param name="env">The environment to use.</param>
/// <param name="outputColumnName">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param>
/// <param name="inputColumnName">Name of the column to transform. If set to <see langword="null"/>, the value of the <paramref name="outputColumnName"/> will be used as source.</param>
/// <param name="labelColumn">Name of the column to use for labels.</param>
/// <param name="labelColumnName">Name of the column to use for labels.</param>
/// <param name="slotsInOutput">The maximum number of slots to preserve in the output. The number of slots to preserve is taken across all input columns.</param>
/// <param name="numBins">Max number of bins used to approximate mutual information between each input column and the label column. Power of 2 recommended.</param>
/// <example>
Expand All @@ -157,8 +157,8 @@ internal MutualInformationFeatureSelectingEstimator(IHostEnvironment env,
/// </format>
/// </example>
internal MutualInformationFeatureSelectingEstimator(IHostEnvironment env, string outputColumnName, string inputColumnName = null,
string labelColumn = Defaults.LabelColumn, int slotsInOutput = Defaults.SlotsInOutput, int numBins = Defaults.NumBins)
: this(env, labelColumn, slotsInOutput, numBins, (outputColumnName, inputColumnName ?? outputColumnName))
string labelColumnName = Defaults.LabelColumnName, int slotsInOutput = Defaults.SlotsInOutput, int numBins = Defaults.NumBins)
: this(env, labelColumnName, slotsInOutput, numBins, (outputColumnName, inputColumnName ?? outputColumnName))
{
}

Expand All @@ -181,7 +181,7 @@ public ITransformer Fit(IDataView input)
}
var colArr = colSet.ToArray();
var colSizes = new int[colArr.Length];
var scores = MutualInformationFeatureSelectionUtils.TrainCore(_host, input, _labelColumn, colArr, _numBins, colSizes);
var scores = MutualInformationFeatureSelectionUtils.TrainCore(_host, input, _labelColumnName, colArr, _numBins, colSizes);
sw.Stop();
ch.Info("Finished mutual information computation in {0}", sw.Elapsed);

Expand Down Expand Up @@ -249,11 +249,11 @@ internal static IDataTransform Create(IHostEnvironment env, Options options, IDa
host.CheckValue(input, nameof(input));
host.CheckNonEmpty(options.Columns, nameof(options.Columns));
host.CheckUserArg(options.SlotsInOutput > 0, nameof(options.SlotsInOutput));
host.CheckNonWhiteSpace(options.LabelColumn, nameof(options.LabelColumn));
host.CheckNonWhiteSpace(options.LabelColumnName, nameof(options.LabelColumnName));
host.Check(options.NumBins > 1, "numBins must be greater than 1.");

(string outputColumnName, string inputColumnName)[] cols = options.Columns.Select(col => (col, col)).ToArray();
return new MutualInformationFeatureSelectingEstimator(env, options.LabelColumn, options.SlotsInOutput, options.NumBins, cols).Fit(input).Transform(input) as IDataTransform;
return new MutualInformationFeatureSelectingEstimator(env, options.LabelColumnName, options.SlotsInOutput, options.NumBins, cols).Fit(input).Transform(input) as IDataTransform;
}

/// <summary>
Expand Down Expand Up @@ -424,14 +424,14 @@ public float[][] GetScores(IDataView input, string labelColumnName, string[] col

if (!schema.TryGetColumnIndex(labelColumnName, out int labelCol))
{
throw _host.ExceptUserArg(nameof(MutualInformationFeatureSelectingEstimator.Options.LabelColumn),
throw _host.ExceptUserArg(nameof(MutualInformationFeatureSelectingEstimator.Options.LabelColumnName),
"Label column '{0}' not found", labelColumnName);
}

var labelType = schema[labelCol].Type;
if (!IsValidColumnType(labelType))
{
throw _host.ExceptUserArg(nameof(MutualInformationFeatureSelectingEstimator.Options.LabelColumn),
throw _host.ExceptUserArg(nameof(MutualInformationFeatureSelectingEstimator.Options.LabelColumnName),
"Label column '{0}' does not have compatible type", labelColumnName);
}

Expand Down
2 changes: 1 addition & 1 deletion test/BaselineOutput/Common/EntryPoints/core_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18485,7 +18485,7 @@
"IsNullable": false
},
{
"Name": "LabelColumn",
"Name": "LabelColumnName",
"Type": "String",
"Desc": "Column to use for labels",
"Aliases": [
Expand Down

0 comments on commit e7a49e5

Please sign in to comment.