diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/LogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/LogisticRegression.cs deleted file mode 100644 index 38e6588079..0000000000 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/LogisticRegression.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using Microsoft.ML.Data; - -namespace Microsoft.ML.Samples.Dynamic -{ - public static class LogisticRegressionExample - { - public static void Example() - { - var ml = new MLContext(); - - // Downloading a classification dataset from github.com/dotnet/machinelearning. - // It will be stored in the same path as the executable - var dataFilePath = SamplesUtils.DatasetUtils.DownloadAdultDataset(); - - // Data Preview - // 1. Column: age (numeric) - // 2. Column: workclass (text/categorical) - // 3. Column: fnlwgt (numeric) - // 4. Column: education (text/categorical) - // 5. Column: education-num (numeric) - // 6. Column: marital-status (text/categorical) - // 7. Column: occupation (text/categorical) - // 8. Column: relationship (text/categorical) - // 9. Column: ethnicity (text/categorical) - // 10. Column: sex (text/categorical) - // 11. Column: capital-gain (numeric) - // 12. Column: capital-loss (numeric) - // 13. Column: hours-per-week (numeric) - // 14. Column: native-country (text/categorical) - // 15. Column: Column [Label]: IsOver50K (boolean) - - var loader = ml.Data.CreateTextLoader(new TextLoader.Options - { - Separators = new[] { ',' }, - HasHeader = true, - Columns = new[] - { - new TextLoader.Column("age", DataKind.Single, 0), - new TextLoader.Column("workclass", DataKind.String, 1), - new TextLoader.Column("fnlwgt", DataKind.Single, 2), - new TextLoader.Column("education", DataKind.String, 3), - new TextLoader.Column("education-num", DataKind.Single, 4), - new TextLoader.Column("marital-status", DataKind.String, 5), - new TextLoader.Column("occupation", DataKind.String, 6), - new TextLoader.Column("relationship", DataKind.String, 7), - new TextLoader.Column("ethnicity", DataKind.String, 8), - new TextLoader.Column("sex", DataKind.String, 9), - new TextLoader.Column("capital-gain", DataKind.Single, 10), - new TextLoader.Column("capital-loss", DataKind.Single, 11), - new TextLoader.Column("hours-per-week", DataKind.Single, 12), - new TextLoader.Column("native-country", DataKind.String, 13), - new TextLoader.Column("Label", DataKind.Boolean, 14) - } - }); - - IDataView data = loader.Load(dataFilePath); - - var split = ml.Data.TrainTestSplit(data, testFraction: 0.2); - - var pipeline = ml.Transforms.Concatenate("Text", "workclass", "education", "marital-status", - "relationship", "ethnicity", "sex", "native-country") - .Append(ml.Transforms.Text.FeaturizeText("TextFeatures", "Text")) - .Append(ml.Transforms.Concatenate("Features", "TextFeatures", "age", "fnlwgt", - "education-num", "capital-gain", "capital-loss", "hours-per-week")) - .Append(ml.BinaryClassification.Trainers.LbfgsLogisticRegression()); - - var model = pipeline.Fit(split.TrainSet); - - var dataWithPredictions = model.Transform(split.TestSet); - - var metrics = ml.BinaryClassification.Evaluate(dataWithPredictions); - - Console.WriteLine($"Accuracy: {metrics.Accuracy}"); // 0.80 - Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve}"); // 0.64 - Console.WriteLine($"F1 Score: {metrics.F1Score}"); // 0.39 - - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision}"); // 0.81 - Console.WriteLine($"Negative Recall: {metrics.NegativeRecall}"); // 0.96 - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision}"); // 0.68 - Console.WriteLine($"Positive Recall: {metrics.PositiveRecall}"); // 0.27 - - Console.ReadLine(); - } - } -} diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude new file mode 100644 index 0000000000..50555baf04 --- /dev/null +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.ML.Data; +<# if (TrainerOptions != null) { #> +<#=OptionsInclude#> +<# } #> + +namespace Microsoft.ML.Samples.Dynamic.Trainers.BinaryClassification +{ + public static class <#=ClassName#> + {<#=Comments#> + public static void Example() + { + // Create a new context for ML.NET operations. It can be used for exception tracking and logging, + // as a catalog of available operations and as the source of randomness. + // Setting the seed to a fixed number in this example to make outputs deterministic. + var mlContext = new MLContext(seed: 0); + + // Create a list of training data points. + var dataPoints = GenerateRandomDataPoints(1000); + + // Convert the list of data points to an IDataView object, which is consumable by ML.NET API. + var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); + +<# if (TrainerOptions == null) { #> + // Define the trainer. + var pipeline = mlContext.BinaryClassification.Trainers.<#=Trainer#>(); +<# } else { #> + // Define trainer options. + var options = new <#=TrainerOptions#>; + + // Define the trainer. + var pipeline = mlContext.BinaryClassification.Trainers.<#=Trainer#>(options); +<# } #> + + // Train the model. + var model = pipeline.Fit(trainingData); + + // Create testing data. Use different random seed to make it different from training data. + var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + + // Run the model on test data set. + var transformedTestData = model.Transform(testData); + + // Convert IDataView object to a list. + var predictions = mlContext.Data.CreateEnumerable(transformedTestData, reuseRowObject: false).ToList(); + + // Look at 5 predictions + foreach (var p in predictions.Take(5)) + Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + + <#=ExpectedOutputPerInstance#> + <# string Evaluator = IsCalibrated ? "Evaluate" : "EvaluateNonCalibrated"; #> + + // Evaluate the overall metrics + var metrics = mlContext.BinaryClassification.<#=Evaluator#>(transformedTestData); + SamplesUtils.ConsoleUtils.PrintMetrics(metrics); + + <#=ExpectedOutput#> + } + + private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + { + var random = new Random(seed); + float randomFloat() => (float)random.NextDouble(); + for (int i = 0; i < count; i++) + { + var label = randomFloat() > 0.5f; + yield return new DataPoint + { + Label = label, + // Create random features that are correlated with the label. + // For data points with false label, the feature values are slightly increased by adding a constant. + Features = Enumerable.Repeat(label, 50).Select(x => x ? randomFloat() : randomFloat() + <#=DataSepValue#>).ToArray() + }; + } + } + + // Example with label and 50 feature values. A data set is a collection of such examples. + private class DataPoint + { + public bool Label { get; set; } + [VectorType(50)] + public float[] Features { get; set; } + } + + // Class used to capture predictions. + private class Prediction + { + // Original label. + public bool Label { get; set; } + // Predicted label from the trainer. + public bool PredictedLabel { get; set; } + } + } +} \ No newline at end of file diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.tt index 9648bd8410..a0362ee9dd 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.tt @@ -1,5 +1,4 @@ <#@ include file="TreeSamplesTemplate.ttinclude"#> - <#+ string ClassName="FastForest"; string Trainer = "FastForest"; diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.tt index 14bc406273..3deb50e6c2 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.tt @@ -1,5 +1,4 @@ <#@ include file="TreeSamplesTemplate.ttinclude"#> - <#+ string ClassName="FastForestWithOptions"; string Trainer = "FastForest"; diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.tt index 58f233a04a..4d0a737ebc 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.tt @@ -1,5 +1,4 @@ <#@ include file="TreeSamplesTemplate.ttinclude"#> - <#+ string ClassName="FastTree"; string Trainer = "FastTree"; diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.tt index d27f82391e..f12941d9f2 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.tt @@ -1,5 +1,4 @@ <#@ include file="TreeSamplesTemplate.ttinclude"#> - <#+ string ClassName="FastTreeWithOptions"; string Trainer = "FastTree"; diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs new file mode 100644 index 0000000000..7ce8b9fb27 --- /dev/null +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.ML.Data; + +namespace Microsoft.ML.Samples.Dynamic.Trainers.BinaryClassification +{ + public static class LbfgsLogisticRegression + { + public static void Example() + { + // Create a new context for ML.NET operations. It can be used for exception tracking and logging, + // as a catalog of available operations and as the source of randomness. + // Setting the seed to a fixed number in this example to make outputs deterministic. + var mlContext = new MLContext(seed: 0); + + // Create a list of training data points. + var dataPoints = GenerateRandomDataPoints(1000); + + // Convert the list of data points to an IDataView object, which is consumable by ML.NET API. + var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); + + // Define the trainer. + var pipeline = mlContext.BinaryClassification.Trainers.LbfgsLogisticRegression(); + + // Train the model. + var model = pipeline.Fit(trainingData); + + // Create testing data. Use different random seed to make it different from training data. + var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + + // Run the model on test data set. + var transformedTestData = model.Transform(testData); + + // Convert IDataView object to a list. + var predictions = mlContext.Data.CreateEnumerable(transformedTestData, reuseRowObject: false).ToList(); + + // Look at 5 predictions + foreach (var p in predictions.Take(5)) + Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + + // Expected output: + // Label: True, Prediction: True + // Label: False, Prediction: True + // Label: True, Prediction: True + // Label: True, Prediction: True + // Label: False, Prediction: False + + // Evaluate the overall metrics + var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + SamplesUtils.ConsoleUtils.PrintMetrics(metrics); + + // Expected output: + // Accuracy: 0.88 + // AUC: 0.96 + // F1 Score: 0.87 + // Negative Precision: 0.90 + // Negative Recall: 0.87 + // Positive Precision: 0.86 + // Positive Recall: 0.89 + // Log Loss: 0.38 + // Log Loss Reduction: 0.62 + // Entropy: 1.00 + } + + private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + { + var random = new Random(seed); + float randomFloat() => (float)random.NextDouble(); + for (int i = 0; i < count; i++) + { + var label = randomFloat() > 0.5f; + yield return new DataPoint + { + Label = label, + // Create random features that are correlated with the label. + // For data points with false label, the feature values are slightly increased by adding a constant. + Features = Enumerable.Repeat(label, 50).Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; + } + } + + // Example with label and 50 feature values. A data set is a collection of such examples. + private class DataPoint + { + public bool Label { get; set; } + [VectorType(50)] + public float[] Features { get; set; } + } + + // Class used to capture predictions. + private class Prediction + { + // Original label. + public bool Label { get; set; } + // Predicted label from the trainer. + public bool PredictedLabel { get; set; } + } + } +} diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.tt new file mode 100644 index 0000000000..422053240f --- /dev/null +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.tt @@ -0,0 +1,30 @@ +<#@ include file="BinaryClassification.ttinclude"#> +<#+ +string ClassName="LbfgsLogisticRegression"; +string Trainer = "LbfgsLogisticRegression"; +string TrainerOptions = null; +bool IsCalibrated = true; + +string DataSepValue = "0.1f"; +string OptionsInclude = ""; +string Comments= ""; + +string ExpectedOutputPerInstance= @"// Expected output: + // Label: True, Prediction: True + // Label: False, Prediction: True + // Label: True, Prediction: True + // Label: True, Prediction: True + // Label: False, Prediction: False"; + +string ExpectedOutput = @"// Expected output: + // Accuracy: 0.88 + // AUC: 0.96 + // F1 Score: 0.87 + // Negative Precision: 0.90 + // Negative Recall: 0.87 + // Positive Precision: 0.86 + // Positive Recall: 0.89 + // Log Loss: 0.38 + // Log Loss Reduction: 0.62 + // Entropy: 1.00"; +#> \ No newline at end of file diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs new file mode 100644 index 0000000000..3f65cbfd8f --- /dev/null +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.ML.Data; +using Microsoft.ML.Trainers; + +namespace Microsoft.ML.Samples.Dynamic.Trainers.BinaryClassification +{ + public static class LbfgsLogisticRegressionWithOptions + { + public static void Example() + { + // Create a new context for ML.NET operations. It can be used for exception tracking and logging, + // as a catalog of available operations and as the source of randomness. + // Setting the seed to a fixed number in this example to make outputs deterministic. + var mlContext = new MLContext(seed: 0); + + // Create a list of training data points. + var dataPoints = GenerateRandomDataPoints(1000); + + // Convert the list of data points to an IDataView object, which is consumable by ML.NET API. + var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); + + // Define trainer options. + var options = new LbfgsLogisticRegressionBinaryTrainer.Options() + { + MaximumNumberOfIterations = 100, + OptmizationTolerance = 1e-8f, + L2Regularization = 0.01f + }; + + // Define the trainer. + var pipeline = mlContext.BinaryClassification.Trainers.LbfgsLogisticRegression(options); + + // Train the model. + var model = pipeline.Fit(trainingData); + + // Create testing data. Use different random seed to make it different from training data. + var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + + // Run the model on test data set. + var transformedTestData = model.Transform(testData); + + // Convert IDataView object to a list. + var predictions = mlContext.Data.CreateEnumerable(transformedTestData, reuseRowObject: false).ToList(); + + // Look at 5 predictions + foreach (var p in predictions.Take(5)) + Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + + // Expected output: + // Label: True, Prediction: True + // Label: False, Prediction: True + // Label: True, Prediction: True + // Label: True, Prediction: True + // Label: False, Prediction: False + + // Evaluate the overall metrics + var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + SamplesUtils.ConsoleUtils.PrintMetrics(metrics); + + // Expected output: + // Accuracy: 0.87 + // AUC: 0.96 + // F1 Score: 0.87 + // Negative Precision: 0.89 + // Negative Recall: 0.87 + // Positive Precision: 0.86 + // Positive Recall: 0.88 + // Log Loss: 0.37 + // Log Loss Reduction: 0.63 + // Entropy: 1.00 + } + + private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + { + var random = new Random(seed); + float randomFloat() => (float)random.NextDouble(); + for (int i = 0; i < count; i++) + { + var label = randomFloat() > 0.5f; + yield return new DataPoint + { + Label = label, + // Create random features that are correlated with the label. + // For data points with false label, the feature values are slightly increased by adding a constant. + Features = Enumerable.Repeat(label, 50).Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; + } + } + + // Example with label and 50 feature values. A data set is a collection of such examples. + private class DataPoint + { + public bool Label { get; set; } + [VectorType(50)] + public float[] Features { get; set; } + } + + // Class used to capture predictions. + private class Prediction + { + // Original label. + public bool Label { get; set; } + // Predicted label from the trainer. + public bool PredictedLabel { get; set; } + } + } +} diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.tt new file mode 100644 index 0000000000..e1bf4444bf --- /dev/null +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.tt @@ -0,0 +1,35 @@ +<#@ include file="BinaryClassification.ttinclude"#> +<#+ +string ClassName="LbfgsLogisticRegressionWithOptions"; +string Trainer = "LbfgsLogisticRegression"; +string TrainerOptions = @"LbfgsLogisticRegressionBinaryTrainer.Options() + { + MaximumNumberOfIterations = 100, + OptmizationTolerance = 1e-8f, + L2Regularization = 0.01f + }"; +bool IsCalibrated = true; + +string DataSepValue = "0.1f"; +string OptionsInclude = "using Microsoft.ML.Trainers;"; +string Comments= ""; + +string ExpectedOutputPerInstance= @"// Expected output: + // Label: True, Prediction: True + // Label: False, Prediction: True + // Label: True, Prediction: True + // Label: True, Prediction: True + // Label: False, Prediction: False"; + +string ExpectedOutput = @"// Expected output: + // Accuracy: 0.87 + // AUC: 0.96 + // F1 Score: 0.87 + // Negative Precision: 0.89 + // Negative Recall: 0.87 + // Positive Precision: 0.86 + // Positive Recall: 0.88 + // Log Loss: 0.37 + // Log Loss Reduction: 0.63 + // Entropy: 1.00"; +#> \ No newline at end of file diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude index b25c54f2a8..3c0003a19e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude @@ -1,99 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.ML.Data; -<# if (TrainerOptions != null) { #> -using Microsoft.ML.Trainers.FastTree; -<# } #> - -namespace Microsoft.ML.Samples.Dynamic.Trainers.BinaryClassification -{ - public static class <#=ClassName#> - { +<#@ include file="BinaryClassification.ttinclude"#> +<#+ +string DataSepValue = "0.03f"; +string OptionsInclude = "using Microsoft.ML.Trainers.FastTree;"; +string Comments= @" // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree. - public static void Example() - { - // Create a new context for ML.NET operations. It can be used for exception tracking and logging, - // as a catalog of available operations and as the source of randomness. - // Setting the seed to a fixed number in this example to make outputs deterministic. - var mlContext = new MLContext(seed: 0); - - // Create a list of training data points. - var dataPoints = GenerateRandomDataPoints(1000); - - // Convert the list of data points to an IDataView object, which is consumable by ML.NET API. - var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); - -<# if (TrainerOptions == null) { #> - // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.<#=Trainer#>(); -<# } else { #> - // Define trainer options. - var options = new <#=TrainerOptions#>; - - // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.<#=Trainer#>(options); -<# } #> - - // Train the model. - var model = pipeline.Fit(trainingData); - - // Create testing data. Use different random seed to make it different from training data. - var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); - - // Run the model on test data set. - var transformedTestData = model.Transform(testData); - - // Convert IDataView object to a list. - var predictions = mlContext.Data.CreateEnumerable(transformedTestData, reuseRowObject: false).ToList(); - - // Look at 5 predictions - foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); - - <#=ExpectedOutputPerInstance#> - <# string Evaluator = IsCalibrated ? "Evaluate" : "EvaluateNonCalibrated"; #> - - // Evaluate the overall metrics - var metrics = mlContext.BinaryClassification.<#=Evaluator#>(transformedTestData); - SamplesUtils.ConsoleUtils.PrintMetrics(metrics); - - <#=ExpectedOutput#> - } - - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) - { - var random = new Random(seed); - float randomFloat() => (float)random.NextDouble(); - for (int i = 0; i < count; i++) - { - var label = randomFloat() > 0.5f; - yield return new DataPoint - { - Label = label, - // Create random features that are correlated with the label. - // For data points with false label, the feature values are slightly increased by adding a constant. - Features = Enumerable.Repeat(label, 50).Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() - }; - } - } - - // Example with label and 50 feature values. A data set is a collection of such examples. - private class DataPoint - { - public bool Label { get; set; } - [VectorType(50)] - public float[] Features { get; set; } - } - - // Class used to capture predictions. - private class Prediction - { - // Original label. - public bool Label { get; set; } - // Predicted label from the trainer. - public bool PredictedLabel { get; set; } - } - } -} \ No newline at end of file + // Microsoft.ML.FastTree."; +#> \ No newline at end of file diff --git a/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj b/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj index 9772e70704..8d83cc95bd 100644 --- a/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj +++ b/docs/samples/Microsoft.ML.Samples/Microsoft.ML.Samples.csproj @@ -46,6 +46,16 @@ True FastTreeWithOptions.tt + + True + True + LbfgsLogisticRegression.tt + + + True + True + LbfgsLogisticRegressionWithOptions.tt + @@ -72,6 +82,14 @@ TextTemplatingFileGenerator FastTreeWithOptions.cs + + LbfgsLogisticRegressionWithOptions.cs + TextTemplatingFileGenerator + + + TextTemplatingFileGenerator + LbfgsLogisticRegression.cs + OnlineGradientDescent.cs TextTemplatingFileGenerator @@ -115,6 +133,16 @@ True FastTreeWithOptions.tt + + True + True + LbfgsLogisticRegression.tt + + + True + True + LbfgsLogisticRegressionWithOptions.tt + True True diff --git a/src/Microsoft.ML.StandardTrainers/StandardTrainersCatalog.cs b/src/Microsoft.ML.StandardTrainers/StandardTrainersCatalog.cs index 0047276e78..76b963d6cf 100644 --- a/src/Microsoft.ML.StandardTrainers/StandardTrainersCatalog.cs +++ b/src/Microsoft.ML.StandardTrainers/StandardTrainersCatalog.cs @@ -512,7 +512,7 @@ public static OnlineGradientDescentTrainer OnlineGradientDescent(this Regression /// /// /// /// /// @@ -536,6 +536,13 @@ public static LbfgsLogisticRegressionBinaryTrainer LbfgsLogisticRegression(this /// /// The binary classification catalog trainer object. /// Advanced arguments to the algorithm. + /// + /// + /// + /// + /// public static LbfgsLogisticRegressionBinaryTrainer LbfgsLogisticRegression(this BinaryClassificationCatalog.BinaryClassificationTrainers catalog, LROptions options) { Contracts.CheckValue(catalog, nameof(catalog));