Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
artidoro committed Apr 17, 2019
1 parent 09fbb77 commit 1877e7d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 48 deletions.
Expand Up @@ -35,11 +35,14 @@ public static void Example()
// Run the model on test data set.
var transformedTestData = model.Transform(testData);

// Take the top 5 rows.
var topTransformedTestData = mlContext.Data.TakeRows(transformedTestData, 5);

// Convert IDataView object to a list.
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data.CreateEnumerable<Prediction>(topTransformedTestData, reuseRowObject: false).ToList();

// Look at 5 predictions
foreach (var p in predictions.Take(5))
// Print 5 predictions.
foreach (var p in predictions)
Console.WriteLine($"Label: {p.Label}, Score: {p.Score}");

// Expected output:
Expand All @@ -49,7 +52,7 @@ public static void Example()
// Label: 3, Score: -8.178633
// Label: 1, Score: -17.09313

// Evaluate the overall metrics
// Evaluate the overall metrics.
var metrics = mlContext.Ranking.Evaluate(transformedTestData);
PrintMetrics(metrics);

Expand Down Expand Up @@ -81,8 +84,8 @@ private class DataPoint
{
[KeyType(5)]
public uint Label { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[VectorType(50)]
public float[] Features { get; set; }
}
Expand Down
Expand Up @@ -32,7 +32,9 @@ public static void Example()
// Create a simpler model by penalizing usage of new features.
FeatureFirstUsePenalty = 0.1,
// Reduce the number of trees to 50.
NumberOfTrees = 50
NumberOfTrees = 50,
// Specify the row group column name.
RowGroupColumnName = "GroupId"
};

// Define the trainer.
Expand All @@ -47,27 +49,30 @@ public static void Example()
// Run the model on test data set.
var transformedTestData = model.Transform(testData);

// Take the top 5 rows.
var topTransformedTestData = mlContext.Data.TakeRows(transformedTestData, 5);

// Convert IDataView object to a list.
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data.CreateEnumerable<Prediction>(topTransformedTestData, reuseRowObject: false).ToList();

// Look at 5 predictions
foreach (var p in predictions.Take(5))
// Print 5 predictions.
foreach (var p in predictions)
Console.WriteLine($"Label: {p.Label}, Score: {p.Score}");

// Expected output:
// Label: 5, Score: 8.098782
// Label: 1, Score: -11.2527
// Label: 3, Score: -10.89519
// Label: 3, Score: -5.050685
// Label: 1, Score: -10.44891
// Label: 5, Score: 8.807633
// Label: 1, Score: -10.71331
// Label: 3, Score: -8.134147
// Label: 3, Score: -6.545538
// Label: 1, Score: -10.27982

// Evaluate the overall metrics
// Evaluate the overall metrics.
var metrics = mlContext.Ranking.Evaluate(transformedTestData);
PrintMetrics(metrics);

// Expected output:
// DCG: @1:41.03, @2:60.07, @3:74.30
// NDCG: @1:0.97, @2:0.93, @3:0.97
// DCG: @1:40.57, @2:61.21, @3:74.11
// NDCG: @1:0.96, @2:0.95, @3:0.97
}

private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int seed = 0, int groupSize = 10)
Expand All @@ -93,8 +98,8 @@ private class DataPoint
{
[KeyType(5)]
public uint Label { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[VectorType(50)]
public float[] Features { get; set; }
}
Expand Down
Expand Up @@ -9,7 +9,9 @@ string TrainerOptions = @"FastTreeRankingTrainer.Options
// Create a simpler model by penalizing usage of new features.
FeatureFirstUsePenalty = 0.1,
// Reduce the number of trees to 50.
NumberOfTrees = 50
NumberOfTrees = 50,
// Specify the row group column name.
RowGroupColumnName = ""GroupId""
}";

string OptionsInclude = "using Microsoft.ML.Trainers.FastTree;";
Expand All @@ -18,13 +20,13 @@ string Comments= @"
// <a href=""https://www.nuget.org/packages/Microsoft.ML.FastTree/"">Microsoft.ML.FastTree</a>.";

string ExpectedOutputPerInstance = @"// Expected output:
// Label: 5, Score: 8.098782
// Label: 1, Score: -11.2527
// Label: 3, Score: -10.89519
// Label: 3, Score: -5.050685
// Label: 1, Score: -10.44891";
// Label: 5, Score: 8.807633
// Label: 1, Score: -10.71331
// Label: 3, Score: -8.134147
// Label: 3, Score: -6.545538
// Label: 1, Score: -10.27982";

string ExpectedOutput = @"// Expected output:
// DCG: @1:41.03, @2:60.07, @3:74.30
// NDCG: @1:0.97, @2:0.93, @3:0.97";
// DCG: @1:40.57, @2:61.21, @3:74.11
// NDCG: @1:0.96, @2:0.95, @3:0.97";
#>
Expand Up @@ -35,11 +35,14 @@ public static void Example()
// Run the model on test data set.
var transformedTestData = model.Transform(testData);

// Take the top 5 rows.
var topTransformedTestData = mlContext.Data.TakeRows(transformedTestData, 5);

// Convert IDataView object to a list.
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data.CreateEnumerable<Prediction>(topTransformedTestData, reuseRowObject: false).ToList();

// Look at 5 predictions
foreach (var p in predictions.Take(5))
// Print 5 predictions.
foreach (var p in predictions)
Console.WriteLine($"Label: {p.Label}, Score: {p.Score}");

// Expected output:
Expand All @@ -49,7 +52,7 @@ public static void Example()
// Label: 3, Score: -2.151812
// Label: 1, Score: -4.089102

// Evaluate the overall metrics
// Evaluate the overall metrics.
var metrics = mlContext.Ranking.Evaluate(transformedTestData);
PrintMetrics(metrics);

Expand Down Expand Up @@ -81,8 +84,8 @@ private class DataPoint
{
[KeyType(5)]
public uint Label { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[VectorType(50)]
public float[] Features { get; set; }
}
Expand Down
Expand Up @@ -50,11 +50,14 @@ public static void Example()
// Run the model on test data set.
var transformedTestData = model.Transform(testData);

// Take the top 5 rows.
var topTransformedTestData = mlContext.Data.TakeRows(transformedTestData, 5);

// Convert IDataView object to a list.
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data.CreateEnumerable<Prediction>(topTransformedTestData, reuseRowObject: false).ToList();

// Look at 5 predictions
foreach (var p in predictions.Take(5))
// Print 5 predictions.
foreach (var p in predictions)
Console.WriteLine($"Label: {p.Label}, Score: {p.Score}");

// Expected output:
Expand All @@ -64,7 +67,7 @@ public static void Example()
// Label: 3, Score: -0.009396422
// Label: 1, Score: -0.05871891

// Evaluate the overall metrics
// Evaluate the overall metrics.
var metrics = mlContext.Ranking.Evaluate(transformedTestData);
PrintMetrics(metrics);

Expand Down Expand Up @@ -96,8 +99,8 @@ private class DataPoint
{
[KeyType(5)]
public uint Label { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[VectorType(50)]
public float[] Features { get; set; }
}
Expand Down
Expand Up @@ -44,16 +44,19 @@ namespace Samples.Dynamic.Trainers.Ranking
// Run the model on test data set.
var transformedTestData = model.Transform(testData);

// Take the top 5 rows.
var topTransformedTestData = mlContext.Data.TakeRows(transformedTestData, 5);

// Convert IDataView object to a list.
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data.CreateEnumerable<Prediction>(topTransformedTestData, reuseRowObject: false).ToList();

// Look at 5 predictions
foreach (var p in predictions.Take(5))
// Print 5 predictions.
foreach (var p in predictions)
Console.WriteLine($"Label: {p.Label}, Score: {p.Score}");

<#=ExpectedOutputPerInstance#>

// Evaluate the overall metrics
// Evaluate the overall metrics.
var metrics = mlContext.Ranking.Evaluate(transformedTestData);
PrintMetrics(metrics);

Expand Down Expand Up @@ -83,8 +86,8 @@ namespace Samples.Dynamic.Trainers.Ranking
{
[KeyType(5)]
public uint Label { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[KeyType(100)]
public uint GroupId { get; set; }
[VectorType(50)]
public float[] Features { get; set; }
}
Expand Down
9 changes: 9 additions & 0 deletions docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj
Expand Up @@ -284,6 +284,10 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>LightGbmWithOptions.cs</LastGenOutput>
</None>
<None Update="Dynamic\Trainers\MulticlassClassification\NaiveBayes.tt">
<LastGenOutput>NaiveBayes.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
</None>
<None Update="Dynamic\Trainers\MulticlassClassification\PairwiseCoupling.tt">
<LastGenOutput>PairwiseCoupling.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>
Expand Down Expand Up @@ -679,6 +683,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>SdcaNonCalibratedWithOptions.tt</DependentUpon>
</Compile>
<Compile Update="Dynamic\Trainers\MulticlassClassification\NaiveBayes.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>NaiveBayes.tt</DependentUpon>
</Compile>
<Compile Update="Dynamic\Trainers\Ranking\FastTree.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.ML.FastTree/TreeTrainersCatalog.cs
Expand Up @@ -136,7 +136,7 @@ public static class TreeExtensions
/// <example>
/// <format type="text/markdown">
/// <![CDATA[
/// [!code-csharp[FastTreeBinaryClassification](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Ranking/FastTree.cs)]
/// [!code-csharp[FastTree](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Ranking/FastTree.cs)]
/// ]]>
/// </format>
/// </example>
Expand All @@ -163,7 +163,7 @@ public static class TreeExtensions
/// <example>
/// <format type="text/markdown">
/// <![CDATA[
/// [!code-csharp[FastTreeBinaryClassification](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Ranking/FastTreeWithOptions.cs)]
/// [!code-csharp[FastTree](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Ranking/FastTreeWithOptions.cs)]
/// ]]>
/// </format>
/// </example>
Expand Down

0 comments on commit 1877e7d

Please sign in to comment.