From cdf6b3652a58188ac3de98bfcbcd4753622cb908 Mon Sep 17 00:00:00 2001 From: sierralee51 <36902786+sierralee51@users.noreply.github.com> Date: Mon, 1 Jul 2019 19:18:57 -0700 Subject: [PATCH 01/60] reformatted BinaryClassification samples --- .../AveragedPerceptron.cs | 53 ++++++--- .../AveragedPerceptronWithOptions.cs | 53 ++++++--- .../BinaryClassification.ttinclude | 68 ++++++++---- .../Calibrators/FixedPlatt.cs | 61 +++++++---- .../Calibrators/Isotonic.cs | 61 +++++++---- .../BinaryClassification/Calibrators/Naive.cs | 62 +++++++---- .../BinaryClassification/Calibrators/Platt.cs | 62 +++++++---- .../FactorizationMachine.cs | 61 +++++++---- .../BinaryClassification/FastForest.cs | 58 +++++++--- .../FastForestWithOptions.cs | 58 +++++++--- .../Trainers/BinaryClassification/FastTree.cs | 58 +++++++--- .../FastTreeWithOptions.cs | 58 +++++++--- .../FieldAwareFactorizationMachine.cs | 76 ++++++++----- .../FieldAwareFactorizationMachine.tt | 16 ++- ...eldAwareFactorizationMachineWithOptions.cs | 76 ++++++++----- ...eldAwareFactorizationMachineWithOptions.tt | 16 ++- .../Trainers/BinaryClassification/Gam.cs | 103 +++++++++++------- .../BinaryClassification/GamWithOptions.cs | 101 ++++++++++------- .../LbfgsLogisticRegression.cs | 53 ++++++--- .../LbfgsLogisticRegressionWithOptions.cs | 53 ++++++--- .../Trainers/BinaryClassification/LightGbm.cs | 58 +++++++--- .../Trainers/BinaryClassification/LightGbm.tt | 5 +- .../LightGbmWithOptions.cs | 58 +++++++--- .../LightGbmWithOptions.tt | 5 +- .../BinaryClassification/LinearSvm.cs | 53 ++++++--- .../LinearSvmWithOptions.cs | 53 ++++++--- ...atureColumnsBinaryClassification.ttinclude | 64 +++++++---- .../PermutationFeatureImportance.cs | 59 ++++++---- .../BinaryClassification/PriorTrainer.cs | 53 ++++++--- .../SdcaLogisticRegression.cs | 61 +++++++---- .../SdcaLogisticRegressionWithOptions.cs | 61 +++++++---- .../BinaryClassification/SdcaNonCalibrated.cs | 61 +++++++---- .../SdcaNonCalibratedWithOptions.cs | 61 +++++++---- .../BinaryClassification/SgdCalibrated.cs | 53 ++++++--- .../SgdCalibratedWithOptions.cs | 53 ++++++--- .../BinaryClassification/SgdNonCalibrated.cs | 53 ++++++--- .../SgdNonCalibratedWithOptions.cs | 53 ++++++--- .../SymbolicSgdLogisticRegression.cs | 58 +++++++--- .../SymbolicSgdLogisticRegression.tt | 5 +- ...ymbolicSgdLogisticRegressionWithOptions.cs | 58 +++++++--- ...ymbolicSgdLogisticRegressionWithOptions.tt | 5 +- .../TreeSamplesTemplate.ttinclude | 5 +- docs/samples/Microsoft.ML.Samples/Program.cs | 5 +- 43 files changed, 1495 insertions(+), 712 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs index 1506fc1abd..56ae8ce9ff 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs @@ -10,35 +10,44 @@ public static class AveragedPerceptron { 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. + // 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. + // 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.AveragedPerceptron(); + var pipeline = mlContext.BinaryClassification.Trainers + .AveragedPerceptron(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -48,7 +57,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -71,7 +82,9 @@ public static void Example() // Precision || 0.7402 | 0.7061 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -82,13 +95,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -111,9 +128,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs index 748e37be8e..5c3a2b16fc 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs @@ -11,15 +11,17 @@ public static class AveragedPerceptronWithOptions { 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. + // 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. + // 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. @@ -33,23 +35,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.AveragedPerceptron(options); + var pipeline = mlContext.BinaryClassification.Trainers + .AveragedPerceptron(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -59,7 +68,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -82,7 +93,9 @@ public static void Example() // Precision || 0.7402 | 0.7061 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -93,13 +106,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -122,9 +139,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude index 6bc5660d46..8501738bd2 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude @@ -13,63 +13,81 @@ namespace Samples.Dynamic.Trainers.BinaryClassification {<#=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. + // 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. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); <# if (CacheData) { #> - // ML.NET doesn't cache data set by default. Therefore, if one reads a data set from a file and accesses it many times, - // it can be slow due to expensive featurization and disk operations. When the considered data can fit into memory, - // a solution is to cache the data in memory. Caching is especially helpful when working with iterative algorithms + // ML.NET doesn't cache data set by default. Therefore, if one reads a + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); <# } #> <# if (TrainerOptions == null) { #> // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.<#=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); + 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); <#=ExpectedOutputPerInstance#> - <# string Evaluator = IsCalibrated ? "Evaluate" : "EvaluateNonCalibrated"; #> + <# string Evaluator = IsCalibrated ? "Evaluate" : + "EvaluateNonCalibrated"; #> // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.<#=Evaluator#>(transformedTestData); + var metrics = mlContext.BinaryClassification + .<#=Evaluator#>(transformedTestData); + PrintMetrics(metrics); <#=ExpectedOutput#> } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -80,13 +98,17 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -109,9 +131,13 @@ namespace Samples.Dynamic.Trainers.BinaryClassification Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/FixedPlatt.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/FixedPlatt.cs index 1da43a7790..2b56ef63f0 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/FixedPlatt.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/FixedPlatt.cs @@ -9,26 +9,36 @@ public static class FixedPlatt { 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. + // 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); // Download and featurize the dataset. - var data = Microsoft.ML.SamplesUtils.DatasetUtils.LoadFeaturizedAdultDataset(mlContext); + var data = Microsoft.ML.SamplesUtils.DatasetUtils + .LoadFeaturizedAdultDataset(mlContext); + // Leave out 10% of data for testing. - var trainTestData = mlContext.Data.TrainTestSplit(data, testFraction: 0.3); + var trainTestData = mlContext.Data + .TrainTestSplit(data, testFraction: 0.3); - // Create data training pipeline for non calibrated trainer and train Naive calibrator on top of it. - var pipeline = mlContext.BinaryClassification.Trainers.AveragedPerceptron(); + // Create data training pipeline for non calibrated trainer and train + // Naive calibrator on top of it. + var pipeline = mlContext.BinaryClassification.Trainers + .AveragedPerceptron(); - // Fit the pipeline, and get a transformer that knows how to score new data. + // Fit the pipeline, and get a transformer that knows how to score new + // data. var transformer = pipeline.Fit(trainTestData.TrainSet); // Fit this pipeline to the training data. - // Let's score the new data. The score will give us a numerical estimation of the chance that the particular sample - // bears positive sentiment. This estimate is relative to the numbers obtained. + // Let's score the new data. The score will give us a numerical + // estimation of the chance that the particular sample bears positive + // sentiment. This estimate is relative to the numbers obtained. var scoredData = transformer.Transform(trainTestData.TestSet); - var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); + var outScores = mlContext.Data + .CreateEnumerable(scoredData, reuseRowObject: false); + PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView // Score 4.18144 @@ -37,16 +47,24 @@ public static void Example() // Score -2.554229 // Score 5.36571 - // Let's train a calibrator estimator on this scored dataset. The trained calibrator estimator produces a transformer - // that can transform the scored data by adding a new column names "Probability". - var calibratorEstimator = mlContext.BinaryClassification.Calibrators.Platt(slope: -1f, offset: -0.05f); + // Let's train a calibrator estimator on this scored dataset. The + // trained calibrator estimator produces a transformer that can + // transform the scored data by adding a new column names "Probability". + var calibratorEstimator = mlContext.BinaryClassification.Calibrators + .Platt(slope: -1f, offset: -0.05f); + var calibratorTransformer = calibratorEstimator.Fit(scoredData); - // Transform the scored data with a calibrator transfomer by adding a new column names "Probability". - // This column is a calibrated version of the "Score" column, meaning its values are a valid probability value in the [0, 1] interval - // representing the chance that the respective sample bears positive sentiment. + // Transform the scored data with a calibrator transfomer by adding a + // new column names "Probability". This column is a calibrated version + // of the "Score" column, meaning its values are a valid probability + // value in the [0, 1] interval representing the chance that the + // respective sample bears positive sentiment. var finalData = calibratorTransformer.Transform(scoredData); - var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + var outScoresAndProbabilities = mlContext.Data + .CreateEnumerable(finalData, + reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); // Score 4.18144 Probability 0.9856767 // Score -14.10248 Probability 7.890148E-07 @@ -61,10 +79,13 @@ private static void PrintScore(IEnumerable values, int numRows) Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); } - private static void PrintScoreAndProbability(IEnumerable values, int numRows) + private static void PrintScoreAndProbability( + IEnumerable values, int numRows) + { foreach (var value in values.Take(numRows)) - Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", value.Score, "Probability", value.Probability); + Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", + value.Score, "Probability", value.Probability); } private class ScoreValue diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Isotonic.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Isotonic.cs index 15a3162d4e..1b1b63139e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Isotonic.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Isotonic.cs @@ -9,26 +9,35 @@ public static class Isotonic { 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. + // 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); // Download and featurize the dataset. - var data = Microsoft.ML.SamplesUtils.DatasetUtils.LoadFeaturizedAdultDataset(mlContext); + var data = Microsoft.ML.SamplesUtils.DatasetUtils + .LoadFeaturizedAdultDataset(mlContext); + // Leave out 10% of data for testing. - var trainTestData = mlContext.Data.TrainTestSplit(data, testFraction: 0.3); + var trainTestData = mlContext.Data + .TrainTestSplit(data, testFraction: 0.3); - // Create data training pipeline for non calibrated trainer and train Naive calibrator on top of it. - var pipeline = mlContext.BinaryClassification.Trainers.AveragedPerceptron(); + // Create data training pipeline for non calibrated trainer and train + // Naive calibrator on top of it. + var pipeline = mlContext.BinaryClassification.Trainers + .AveragedPerceptron(); - // Fit the pipeline, and get a transformer that knows how to score new data. + // Fit the pipeline, and get a transformer that knows how to score new + // data. var transformer = pipeline.Fit(trainTestData.TrainSet); // Fit this pipeline to the training data. - // Let's score the new data. The score will give us a numerical estimation of the chance that the particular sample - // bears positive sentiment. This estimate is relative to the numbers obtained. + // Let's score the new data. The score will give us a numerical + // estimation of the chance that the particular sample bears positive + // sentiment. This estimate is relative to the numbers obtained. var scoredData = transformer.Transform(trainTestData.TestSet); - var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); + var outScores = mlContext.Data + .CreateEnumerable(scoredData, reuseRowObject: false); PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView @@ -38,16 +47,24 @@ public static void Example() // Score -2.554229 // Score 5.36571 - // Let's train a calibrator estimator on this scored dataset. The trained calibrator estimator produces a transformer - // that can transform the scored data by adding a new column names "Probability". - var calibratorEstimator = mlContext.BinaryClassification.Calibrators.Isotonic(); + // Let's train a calibrator estimator on this scored dataset. The + // trained calibrator estimator produces a transformer that can + // transform the scored data by adding a new column names "Probability". + var calibratorEstimator = mlContext.BinaryClassification.Calibrators + .Isotonic(); + var calibratorTransformer = calibratorEstimator.Fit(scoredData); - // Transform the scored data with a calibrator transfomer by adding a new column names "Probability". - // This column is a calibrated version of the "Score" column, meaning its values are a valid probability value in the [0, 1] interval - // representing the chance that the respective sample bears positive sentiment. + // Transform the scored data with a calibrator transfomer by adding a + // new column names "Probability". This column is a calibrated version + // of the "Score" column, meaning its values are a valid probability + // value in the [0, 1] interval representing the chance that the + // respective sample bears positive sentiment. var finalData = calibratorTransformer.Transform(scoredData); - var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + var outScoresAndProbabilities = mlContext.Data + .CreateEnumerable(finalData, + reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); // Score 4.18144 Probability 0.8 // Score -14.10248 Probability 1E-15 @@ -62,10 +79,14 @@ private static void PrintScore(IEnumerable values, int numRows) Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); } - private static void PrintScoreAndProbability(IEnumerable values, int numRows) + private static void PrintScoreAndProbability( + IEnumerable values, int numRows) + { foreach (var value in values.Take(numRows)) - Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", value.Score, "Probability", value.Probability); + Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", + value.Score, "Probability", value.Probability); + } private class ScoreValue diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Naive.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Naive.cs index 84a004b1c5..054d4f9e31 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Naive.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Naive.cs @@ -9,26 +9,36 @@ public static class Naive { 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. + // 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); // Download and featurize the dataset. - var data = Microsoft.ML.SamplesUtils.DatasetUtils.LoadFeaturizedAdultDataset(mlContext); + var data = Microsoft.ML.SamplesUtils.DatasetUtils + .LoadFeaturizedAdultDataset(mlContext); + // Leave out 10% of data for testing. - var trainTestData = mlContext.Data.TrainTestSplit(data, testFraction: 0.3); + var trainTestData = mlContext.Data + .TrainTestSplit(data, testFraction: 0.3); - // Create data training pipeline for non calibrated trainer and train Naive calibrator on top of it. - var pipeline = mlContext.BinaryClassification.Trainers.AveragedPerceptron(); + // Create data training pipeline for non calibrated trainer and train + // Naive calibrator on top of it. + var pipeline = mlContext.BinaryClassification.Trainers + .AveragedPerceptron(); - // Fit the pipeline, and get a transformer that knows how to score new data. + // Fit the pipeline, and get a transformer that knows how to score new + // data. var transformer = pipeline.Fit(trainTestData.TrainSet); // Fit this pipeline to the training data. - // Let's score the new data. The score will give us a numerical estimation of the chance that the particular sample - // bears positive sentiment. This estimate is relative to the numbers obtained. + // Let's score the new data. The score will give us a numerical + // estimation of the chance that the particular sample bears positive + // sentiment. This estimate is relative to the numbers obtained. var scoredData = transformer.Transform(trainTestData.TestSet); - var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); + var outScores = mlContext.Data + .CreateEnumerable(scoredData, reuseRowObject: false); + PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView // Score 4.18144 @@ -37,16 +47,24 @@ public static void Example() // Score -2.554229 // Score 5.36571 - // Let's train a calibrator estimator on this scored dataset. The trained calibrator estimator produces a transformer - // that can transform the scored data by adding a new column names "Probability". - var calibratorEstimator = mlContext.BinaryClassification.Calibrators.Naive(); + // Let's train a calibrator estimator on this scored dataset. The + // trained calibrator estimator produces a transformer that can + // transform the scored data by adding a new column names "Probability". + var calibratorEstimator = mlContext.BinaryClassification.Calibrators + .Naive(); + var calibratorTransformer = calibratorEstimator.Fit(scoredData); - // Transform the scored data with a calibrator transfomer by adding a new column names "Probability". - // This column is a calibrated version of the "Score" column, meaning its values are a valid probability value in the [0, 1] interval - // representing the chance that the respective sample bears positive sentiment. + // Transform the scored data with a calibrator transfomer by adding a + // new column names "Probability". This column is a calibrated version + // of the "Score" column, meaning its values are a valid probability + // value in the [0, 1] interval representing the chance that the + // respective sample bears positive sentiment. var finalData = calibratorTransformer.Transform(scoredData); - var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + var outScoresAndProbabilities = mlContext.Data + .CreateEnumerable(finalData, + reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); // Score 4.18144 Probability 0.775 // Score -14.10248 Probability 0.01923077 @@ -61,10 +79,14 @@ private static void PrintScore(IEnumerable values, int numRows) Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); } - private static void PrintScoreAndProbability(IEnumerable values, int numRows) + private static void PrintScoreAndProbability( + IEnumerable values, int numRows) + { foreach (var value in values.Take(numRows)) - Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", value.Score, "Probability", value.Probability); + Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", + value.Score, "Probability", value.Probability); + } private class ScoreValue diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Platt.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Platt.cs index aa0d7d0798..709db362e6 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Platt.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Calibrators/Platt.cs @@ -9,26 +9,36 @@ public static class Platt { 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. + // 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); // Download and featurize the dataset. - var data = Microsoft.ML.SamplesUtils.DatasetUtils.LoadFeaturizedAdultDataset(mlContext); + var data = Microsoft.ML.SamplesUtils.DatasetUtils + .LoadFeaturizedAdultDataset(mlContext); + // Leave out 10% of data for testing. - var trainTestData = mlContext.Data.TrainTestSplit(data, testFraction: 0.3); + var trainTestData = mlContext.Data + .TrainTestSplit(data, testFraction: 0.3); - // Create data training pipeline for non calibrated trainer and train Naive calibrator on top of it. - var pipeline = mlContext.BinaryClassification.Trainers.AveragedPerceptron(); + // Create data training pipeline for non calibrated trainer and train + // Naive calibrator on top of it. + var pipeline = mlContext.BinaryClassification.Trainers + .AveragedPerceptron(); - // Fit the pipeline, and get a transformer that knows how to score new data. + // Fit the pipeline, and get a transformer that knows how to score new + // data. var transformer = pipeline.Fit(trainTestData.TrainSet); // Fit this pipeline to the training data. - // Let's score the new data. The score will give us a numerical estimation of the chance that the particular sample - // bears positive sentiment. This estimate is relative to the numbers obtained. + // Let's score the new data. The score will give us a numerical + // estimation of the chance that the particular sample bears positive + // sentiment. This estimate is relative to the numbers obtained. var scoredData = transformer.Transform(trainTestData.TestSet); - var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); + var outScores = mlContext.Data + .CreateEnumerable(scoredData, reuseRowObject: false); + PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView // Score 4.18144 @@ -37,16 +47,24 @@ public static void Example() // Score -2.554229 // Score 5.36571 - // Let's train a calibrator estimator on this scored dataset. The trained calibrator estimator produces a transformer - // that can transform the scored data by adding a new column names "Probability". - var calibratorEstimator = mlContext.BinaryClassification.Calibrators.Platt(); + // Let's train a calibrator estimator on this scored dataset. The + // trained calibrator estimator produces a transformer that can + // transform the scored data by adding a new column names "Probability". + var calibratorEstimator = mlContext.BinaryClassification.Calibrators + .Platt(); + var calibratorTransformer = calibratorEstimator.Fit(scoredData); - // Transform the scored data with a calibrator transfomer by adding a new column names "Probability". - // This column is a calibrated version of the "Score" column, meaning its values are a valid probability value in the [0, 1] interval - // representing the chance that the respective sample bears positive sentiment. + // Transform the scored data with a calibrator transfomer by adding a + // new column names "Probability". This column is a calibrated version + // of the "Score" column, meaning its values are a valid probability + // value in the [0, 1] interval representing the chance that the + // respective sample bears positive sentiment. var finalData = calibratorTransformer.Transform(scoredData); - var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + var outScoresAndProbabilities = mlContext.Data + .CreateEnumerable(finalData, + reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); // Score 4.18144 Probability 0.8511352 // Score -14.10248 Probability 0.001633563 @@ -61,10 +79,14 @@ private static void PrintScore(IEnumerable values, int numRows) Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); } - private static void PrintScoreAndProbability(IEnumerable values, int numRows) + private static void PrintScoreAndProbability( + IEnumerable values, int numRows) + { foreach (var value in values.Take(numRows)) - Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", value.Score, "Probability", value.Probability); + Console.WriteLine("{0, -10} {1, -10} {2, -10} {3, -10}", "Score", + value.Score, "Probability", value.Probability); + } private class ScoreValue diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs index afc9231814..8c3ba88dc0 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs @@ -10,41 +10,52 @@ public static class FactorizationMachine { 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. + // 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. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); - // ML.NET doesn't cache data set by default. Therefore, if one reads a data set from a file and accesses it many times, - // it can be slow due to expensive featurization and disk operations. When the considered data can fit into memory, - // a solution is to cache the data in memory. Caching is especially helpful when working with iterative algorithms + // ML.NET doesn't cache data set by default. Therefore, if one reads a + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.FieldAwareFactorizationMachine(); + var pipeline = mlContext.BinaryClassification.Trainers + .FieldAwareFactorizationMachine(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -54,7 +65,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -77,7 +90,9 @@ public static void Example() // Precision || 0.9063 | 0.8732 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -88,13 +103,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -117,9 +136,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs index b415ae5dc9..16187c6cc7 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs @@ -8,39 +8,49 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastForest { - // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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.FastForest(); + var pipeline = mlContext.BinaryClassification.Trainers + .FastForest(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -50,7 +60,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -73,7 +85,9 @@ public static void Example() // Precision || 0.6182 | 0.5416 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -84,13 +98,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -113,9 +131,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs index 372be0f1fa..5a84f95799 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs @@ -9,19 +9,22 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastForestWithOptions { - // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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. @@ -36,23 +39,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.FastForest(options); + var pipeline = mlContext.BinaryClassification.Trainers + .FastForest(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -62,7 +72,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -85,7 +97,9 @@ public static void Example() // Precision || 0.7072 | 0.7806 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -96,13 +110,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -125,9 +143,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs index d260ec8666..b3585bd5d9 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs @@ -8,39 +8,49 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastTree { - // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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.FastTree(); + var pipeline = mlContext.BinaryClassification.Trainers + .FastTree(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -50,7 +60,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -76,7 +88,9 @@ public static void Example() // Precision || 0.6903 | 0.7716 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -87,13 +101,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -116,9 +134,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs index b02e9b977b..5587f6c4dd 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs @@ -9,19 +9,22 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastTreeWithOptions { - // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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. @@ -36,23 +39,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.FastTree(options); + var pipeline = mlContext.BinaryClassification.Trainers + .FastTree(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -62,7 +72,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -88,7 +100,9 @@ public static void Example() // Precision || 0.6903 | 0.7716 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -99,13 +113,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -128,9 +146,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs index bc2eaef343..0a5c281f58 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs @@ -8,31 +8,41 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FieldAwareFactorizationMachine { - // This example first train a field-aware factorization to binary classification, measure the trained model's quality, and finally + // This example first train a field-aware factorization to binary + // classification, measure the trained model's quality, and finally // use the trained model to make prediction. 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); - // Convert the list of data points to an IDataView object, which is consumable by ML.NET API. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); // Define the trainer. - // This trainer trains field-aware factorization (FFM) for binary classification. See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf - // for the theory behind and https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the training - // algorithm implemented in ML.NET. - var pipeline = mlContext.BinaryClassification.Trainers.FieldAwareFactorizationMachine( + // This trainer trains field-aware factorization (FFM) + //for binary classification. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET. + var pipeline = mlContext.BinaryClassification.Trainers + .FieldAwareFactorizationMachine( // Specify three feature columns! - new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), + nameof(DataPoint.Field2) }, + // Specify binary label's column name. nameof(DataPoint.Label) ); + // Train the model. var model = pipeline.Fit(trainingData); @@ -40,7 +50,8 @@ public static void Example() var transformedTrainingData = model.Transform(trainingData); // Measure the quality of the trained model. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTrainingData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -68,14 +79,18 @@ public static void Example() // Precision || 0.7878 | 0.8235 | // Create prediction function from the trained model. - var engine = mlContext.Model.CreatePredictionEngine(model); + var engine = mlContext.Model + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); - Console.WriteLine($"Actual label: {dataPoint.Label}, predicted label: {result.PredictedLabel}, " + - $"score of being positive class: {result.Score}, and probability of beling positive class: {result.Probability}."); + Console.WriteLine($"Actual label: {dataPoint.Label}, " + + $"predicted label: {result.PredictedLabel}, " + + $"score of being positive class: {result.Score}, " + + $"and probability of beling positive class: " + + $"{result.Probability}."); } // Expected output: @@ -95,7 +110,8 @@ private class DataPoint // Label. public bool Label { get; set; } - // Features from the first field. Note that different fields can have different numbers of features. + // Features from the first field. Note that different fields can have + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -108,8 +124,8 @@ private class DataPoint public float[] Field2 { get; set; } } - // This class defines objects produced by trained model. The trained model maps - // a DataPoint to a Result. + // This class defines objects produced by trained model. The trained model + // maps a DataPoint to a Result. public class Result { // Label. @@ -123,13 +139,16 @@ public class Result } // Function used to create toy data sets. - private static IEnumerable GenerateRandomDataPoints(int exampleCount, int seed = 0) + private static IEnumerable GenerateRandomDataPoints( + int exampleCount, int seed = 0) + { var rnd = new Random(seed); var data = new List(); for (int i = 0; i < exampleCount; ++i) { - // Initialize an example with a random label and an empty feature vector. + // Initialize an example with a random label and an empty feature + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -139,9 +158,10 @@ private static IEnumerable GenerateRandomDataPoints(int exampleCount, }; // Fill feature vectors according the assigned label. - // Notice that features from different fields have different biases and therefore different distributions. - // In practices such as game recommendation, one may use one field to store features from user profile and - // another field to store features from game profile. + // Notice that features from different fields have different biases + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -169,14 +189,20 @@ private static IEnumerable GenerateRandomDataPoints(int exampleCount, } // Function used to show evaluation metrics such as accuracy of predictions. - private static void PrintMetrics(CalibratedBinaryClassificationMetrics metrics) + private static void PrintMetrics( + CalibratedBinaryClassificationMetrics metrics) + { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); Console.WriteLine($"Log Loss Reduction: {metrics.LogLossReduction:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt index 3f41aa671f..d3b1a1086b 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt @@ -3,19 +3,25 @@ string ClassName="FieldAwareFactorizationMachine"; string Trainer = @"FieldAwareFactorizationMachine( // Specify three feature columns! - new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), + nameof(DataPoint.Field2) }, + // Specify binary label's column name. nameof(DataPoint.Label) )"; string OptionsInclude = null; string Comments = @" - // This example first train a field-aware factorization to binary classification, measure the trained model's quality, and finally + // This example first train a field-aware factorization to binary + // classification, measure the trained model's quality, and finally // use the trained model to make prediction."; -string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) for binary classification. See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf - // for the theory behind and https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the training - // algorithm implemented in ML.NET."; +string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) + //for binary classification. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET."; string TrainerOptions = null; diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs index 47e53dfdc3..f68fd8abce 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs @@ -9,26 +9,31 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FieldAwareFactorizationMachineWithOptions { - // This example first train a field-aware factorization to binary classification, measure the trained model's quality, and finally + // This example first train a field-aware factorization to binary + // classification, measure the trained model's quality, and finally // use the trained model to make prediction. 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); - // Convert the list of data points to an IDataView object, which is consumable by ML.NET API. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); // Define trainer options. var options = new FieldAwareFactorizationMachineTrainer.Options { FeatureColumnName = nameof(DataPoint.Field0), - ExtraFeatureColumns = new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + ExtraFeatureColumns = + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, LambdaLinear = 0.001f, @@ -38,10 +43,15 @@ public static void Example() }; // Define the trainer. - // This trainer trains field-aware factorization (FFM) for binary classification. See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf - // for the theory behind and https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the training - // algorithm implemented in ML.NET. - var pipeline = mlContext.BinaryClassification.Trainers.FieldAwareFactorizationMachine(options); + // This trainer trains field-aware factorization (FFM) + // for binary classification. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET. + var pipeline = mlContext.BinaryClassification.Trainers + .FieldAwareFactorizationMachine(options); + // Train the model. var model = pipeline.Fit(trainingData); @@ -50,7 +60,8 @@ public static void Example() var transformedTrainingData = model.Transform(trainingData); // Measure the quality of the trained model. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTrainingData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -78,14 +89,18 @@ public static void Example() // Precision || 0.7425 | 0.8319 | // Create prediction function from the trained model. - var engine = mlContext.Model.CreatePredictionEngine(model); + var engine = mlContext.Model + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); - Console.WriteLine($"Actual label: {dataPoint.Label}, predicted label: {result.PredictedLabel}, " + - $"score of being positive class: {result.Score}, and probability of beling positive class: {result.Probability}."); + Console.WriteLine($"Actual label: {dataPoint.Label}, " + + $"predicted label: {result.PredictedLabel}, " + + $"score of being positive class: {result.Score}, " + + $"and probability of beling positive class: " + + $"{result.Probability}."); } // Expected output: @@ -105,7 +120,8 @@ private class DataPoint // Label. public bool Label { get; set; } - // Features from the first field. Note that different fields can have different numbers of features. + // Features from the first field. Note that different fields can have + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -118,8 +134,8 @@ private class DataPoint public float[] Field2 { get; set; } } - // This class defines objects produced by trained model. The trained model maps - // a DataPoint to a Result. + // This class defines objects produced by trained model. The trained model + // maps a DataPoint to a Result. public class Result { // Label. @@ -133,13 +149,16 @@ public class Result } // Function used to create toy data sets. - private static IEnumerable GenerateRandomDataPoints(int exampleCount, int seed = 0) + private static IEnumerable GenerateRandomDataPoints( + int exampleCount, int seed = 0) + { var rnd = new Random(seed); var data = new List(); for (int i = 0; i < exampleCount; ++i) { - // Initialize an example with a random label and an empty feature vector. + // Initialize an example with a random label and an empty feature + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -149,9 +168,10 @@ private static IEnumerable GenerateRandomDataPoints(int exampleCount, }; // Fill feature vectors according the assigned label. - // Notice that features from different fields have different biases and therefore different distributions. - // In practices such as game recommendation, one may use one field to store features from user profile and - // another field to store features from game profile. + // Notice that features from different fields have different biases + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -179,14 +199,20 @@ private static IEnumerable GenerateRandomDataPoints(int exampleCount, } // Function used to show evaluation metrics such as accuracy of predictions. - private static void PrintMetrics(CalibratedBinaryClassificationMetrics metrics) + private static void PrintMetrics( + CalibratedBinaryClassificationMetrics metrics) + { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); Console.WriteLine($"Log Loss Reduction: {metrics.LogLossReduction:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt index c3de9d1882..fafc98de1e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt @@ -6,17 +6,23 @@ string Trainer = "FieldAwareFactorizationMachine"; string OptionsInclude = @"using Microsoft.ML.Trainers;"; string Comments = @" - // This example first train a field-aware factorization to binary classification, measure the trained model's quality, and finally + // This example first train a field-aware factorization to binary + // classification, measure the trained model's quality, and finally // use the trained model to make prediction."; -string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) for binary classification. See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf - // for the theory behind and https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the training - // algorithm implemented in ML.NET."; +string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) + // for binary classification. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET."; string TrainerOptions = @"FieldAwareFactorizationMachineTrainer.Options { FeatureColumnName = nameof(DataPoint.Field0), - ExtraFeatureColumns = new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + ExtraFeatureColumns = + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, LambdaLinear = 0.001f, diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Gam.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Gam.cs index 3b9c36644f..d4ce855e3c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Gam.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/Gam.cs @@ -7,12 +7,14 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class Gam { - // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. var mlContext = new MLContext(); // Create the dataset. @@ -27,30 +29,36 @@ public static void Example() var validSet = dataSets.TestSet; // Create a GAM trainer. - // Use a small number of bins for this example. The setting below means for each feature, - // we divide its range into 16 discrete regions for the training process. Note that these - // regions are not evenly spaced, and that the final model may contain fewer bins, as - // neighboring bins with identical values will be combined. In general, we recommend using - // at least the default number of bins, as a small number of bins limits the capacity of - // the model. - var trainer = mlContext.BinaryClassification.Trainers.Gam(maximumBinCountPerFeature: 16); - - // Fit the model using both of training and validation sets. GAM can use a technique called - // pruning to tune the model to the validation set after training to improve generalization. + // Use a small number of bins for this example. The setting below means + // for each feature, we divide its range into 16 discrete regions for + // the training process. Note that these regions are not evenly spaced, + // and that the final model may contain fewer bins, as neighboring bins + // with identical values will be combined. In general, we recommend + // using at least the default number of bins, as a small number of bins + // limits the capacity of the model. + var trainer = mlContext.BinaryClassification.Trainers + .Gam(maximumBinCountPerFeature: 16); + + // Fit the model using both of training and validation sets. GAM can use + // a technique called pruning to tune the model to the validation set + // after training to improve generalization. var model = trainer.Fit(trainSet, validSet); // Extract the model parameters. var gam = model.Model.SubModel; - // Now we can inspect the parameters of the Generalized Additive Model to understand the fit - // and potentially learn about our dataset. - // First, we will look at the bias; the bias represents the average prediction for the training data. + // Now we can inspect the parameters of the Generalized Additive Model + // to understand the fit and potentially learn about our dataset. First, + // we will look at the bias; the bias represents the average prediction + // for the training data. Console.WriteLine($"Average prediction: {gam.Bias:0.00}"); - // Now look at the shape functions that the model has learned. Similar to a linear model, we have - // one response per feature, and they are independent. Unlike a linear model, this response is a - // generic function instead of a line. Because we have included a bias term, each feature response - // represents the deviation from the average prediction as a function of the feature value. + // Now look at the shape functions that the model has learned. Similar + // to a linear model, we have one response per feature, and they are + // independent. Unlike a linear model, this response is a generic + // function instead of a line. Because we have included a bias term, + // each feature response represents the deviation from the average + // prediction as a function of the feature value. for (int i = 0; i < gam.NumberOfShapeFunctions; i++) { // Break a line. @@ -62,11 +70,14 @@ public static void Example() // Get the bin effects; these are the function values for each bin. var binEffects = gam.GetBinEffects(i); - // Now, write the function to the console. The function is a set of bins, and the corresponding - // function values. You can think of GAMs as building a bar-chart or lookup table for each feature. + // Now, write the function to the console. The function is a set of + // bins, and the corresponding function values. You can think of + // GAMs as building a bar-chart or lookup table for each feature. Console.WriteLine($"Feature{i}"); for (int j = 0; j < binUpperBounds.Count; j++) - Console.WriteLine($"x < {binUpperBounds[j]:0.00} => {binEffects[j]:0.000}"); + Console.WriteLine( + $"x < {binUpperBounds[j]:0.00} => {binEffects[j]:0.000}"); + } // Expected output: @@ -91,18 +102,23 @@ public static void Example() // x < 0.31 => -0.138 // x < ∞ => -0.188 - // Let's consider this output. To score a given example, we look up the first bin where the inequality - // is satisfied for the feature value. We can look at the whole function to get a sense for how the - // model responds to the variable on a global level. - // The model can be seen to reconstruct the parabolic and step-wise function, shifted with respect to the average - // expected output over the training set. Very few bins are used to model the second feature because the GAM model - // discards unchanged bins to create smaller models. - // One last thing to notice is that these feature functions can be noisy. While we know that Feature1 should be - // symmetric, this is not captured in the model. This is due to noise in the data. Common practice is to use - // resampling methods to estimate a confidence interval at each bin. This will help to determine if the effect is - // real or just sampling noise. See for example: - // Tan, Caruana, Hooker, and Lou. "Distill-and-Compare: Auditing Black-Box Models Using Transparent Model - // Distillation." arXiv:1710.06169." + // Let's consider this output. To score a given example, we look up the + // first bin where the inequality is satisfied for the feature value. + // We can look at the whole function to get a sense for how the model + // responds to the variable on a global level.The model can be seen to + // reconstruct the parabolic and step-wise function, shifted with + // respect to the average expected output over the training set. + // Very few bins are used to model the second feature because the GAM + // model discards unchanged bins to create smaller models. One last + // thing to notice is that these feature functions can be noisy. While + // we know that Feature1 should be symmetric, this is not captured in + // the model. This is due to noise in the data. Common practice is to + // use resampling methods to estimate a confidence interval at each bin. + // This will help to determine if the effect is real or just sampling + // noise. See for example: Tan, Caruana, Hooker, and Lou. + // "Distill-and-Compare: Auditing Black-Box Models Using Transparent + // Model Distillation." + // arXiv:1710.06169." } private class Data @@ -114,13 +130,17 @@ private class Data } /// - /// Creates a dataset, an IEnumerable of Data objects, for a GAM sample. Feature1 is a parabola centered around 0, - /// while Feature2 is a simple piecewise function. + /// Creates a dataset, an IEnumerable of Data objects, for a GAM sample. + /// Feature1 is a parabola centered around 0, while Feature2 is a simple + /// piecewise function. /// /// The number of examples to generate. - /// The seed for the random number generator used to produce data. + /// The seed for the random number generator used to + /// produce data. /// - private static IEnumerable GenerateData(int numExamples = 25000, int seed = 1) + private static IEnumerable GenerateData(int numExamples = 25000, + int seed = 1) + { var rng = new Random(seed); float centeredFloat() => (float)(rng.NextDouble() - 0.5); @@ -131,7 +151,8 @@ private static IEnumerable GenerateData(int numExamples = 25000, int seed Features = new float[2] { centeredFloat(), centeredFloat() } }; // Compute the label from the shape functions and add noise. - data.Label = Sigmoid(Parabola(data.Features[0]) + SimplePiecewise(data.Features[1]) + centeredFloat()) > 0.5; + data.Label = Sigmoid(Parabola(data.Features[0]) + + SimplePiecewise(data.Features[1]) + centeredFloat()) > 0.5; yield return data; } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs index e4a408a3ae..d22f238e5d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs @@ -8,12 +8,14 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class GamWithOptions { - // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. var mlContext = new MLContext(); // Create the dataset. @@ -28,14 +30,15 @@ public static void Example() var validSet = dataSets.TestSet; // Create a GAM trainer. - // Use a small number of bins for this example. The setting below means for each feature, - // we divide its range into 16 discrete regions for the training process. Note that these - // regions are not evenly spaced, and that the final model may contain fewer bins, as - // neighboring bins with identical values will be combined. In general, we recommend using - // at least the default number of bins, as a small number of bins limits the capacity of - // the model. - // Also, set the learning rate to half the default to slow down the gradient descent, and - // double the number of iterations to compensate. + // Use a small number of bins for this example. The setting below means + // for each feature, we divide its range into 16 discrete regions for + // the training process. Note that these regions are not evenly spaced, + // and that the final model may contain fewer bins, as neighboring bins + // with identical values will be combined. In general, we recommend + // using at least the default number of bins, as a small number of bins + // limits the capacity of the model. Also, set the learning rate to half + // the default to slow down the gradient descent, and double the number + // of iterations to compensate. var trainer = mlContext.BinaryClassification.Trainers.Gam( new GamBinaryTrainer.Options { NumberOfIterations = 19000, @@ -43,22 +46,26 @@ public static void Example() LearningRate = 0.001 }); - // Fit the model using both of training and validation sets. GAM can use a technique called - // pruning to tune the model to the validation set after training to improve generalization. + // Fit the model using both of training and validation sets. GAM can use + // a technique called pruning to tune the model to the validation set + // after training to improve generalization. var model = trainer.Fit(trainSet, validSet); // Extract the model parameters. var gam = model.Model.SubModel; - // Now we can inspect the parameters of the Generalized Additive Model to understand the fit - // and potentially learn about our dataset. - // First, we will look at the bias; the bias represents the average prediction for the training data. + // Now we can inspect the parameters of the Generalized Additive Model + // to understand the fit and potentially learn about our dataset. First, + // we will look at the bias; the bias represents the average prediction + // for the training data. Console.WriteLine($"Average prediction: {gam.Bias:0.00}"); - // Now look at the shape functions that the model has learned. Similar to a linear model, we have - // one response per feature, and they are independent. Unlike a linear model, this response is a - // generic function instead of a line. Because we have included a bias term, each feature response - // represents the deviation from the average prediction as a function of the feature value. + // Now look at the shape functions that the model has learned. Similar + // to a linear model, we have one response per feature, and they are + // independent. Unlike a linear model, this response is a generic + // function instead of a line. Because we have included a bias term, + // each feature response represents the deviation from the average + // prediction as a function of the feature value. for (int i = 0; i < gam.NumberOfShapeFunctions; i++) { // Break a line. @@ -70,11 +77,13 @@ public static void Example() // Get the bin effects; these are the function values for each bin. var binEffects = gam.GetBinEffects(i); - // Now, write the function to the console. The function is a set of bins, and the corresponding - // function values. You can think of GAMs as building a bar-chart or lookup table for each feature. + // Now, write the function to the console. The function is a set of + // bins, and the corresponding function values. You can think of + // GAMs as building a bar-chart or lookup table for each feature. Console.WriteLine($"Feature{i}"); for (int j = 0; j < binUpperBounds.Count; j++) - Console.WriteLine($"x < {binUpperBounds[j]:0.00} => {binEffects[j]:0.000}"); + Console.WriteLine( + $"x < {binUpperBounds[j]:0.00} => {binEffects[j]:0.000}"); } // Expected output: @@ -99,18 +108,23 @@ public static void Example() // x < 0.31 => -0.138 // x < ∞ => -0.188 - // Let's consider this output. To score a given example, we look up the first bin where the inequality - // is satisfied for the feature value. We can look at the whole function to get a sense for how the - // model responds to the variable on a global level. - // The model can be seen to reconstruct the parabolic and step-wise function, shifted with respect to the average - // expected output over the training set. Very few bins are used to model the second feature because the GAM model - // discards unchanged bins to create smaller models. - // One last thing to notice is that these feature functions can be noisy. While we know that Feature1 should be - // symmetric, this is not captured in the model. This is due to noise in the data. Common practice is to use - // resampling methods to estimate a confidence interval at each bin. This will help to determine if the effect is - // real or just sampling noise. See for example: - // Tan, Caruana, Hooker, and Lou. "Distill-and-Compare: Auditing Black-Box Models Using Transparent Model - // Distillation." arXiv:1710.06169." + // Let's consider this output. To score a given example, we look up the + // first bin where the inequality is satisfied for the feature value. + // We can look at the whole function to get a sense for how the model + // responds to the variable on a global level. The model can be seen to + // reconstruct the parabolic and step-wise function, shifted with + // respect to the average expected output over the training set. Very + // few bins are used to model the second feature because the GAM model + // discards unchanged bins to create smaller models.One last thing to + // notice is that these feature functions can be noisy. While we know + // that Feature1 should be symmetric, this is not captured in the model. + // This is due to noise in the data. Common practice is to use + // resampling methods to estimate a confidence interval at each bin. + // This will help to determine if the effect is real or just sampling + // noise. See for example: Tan, Caruana, Hooker, and Lou. + // "Distill-and-Compare: Auditing Black-Box Models Using Transparent + // Model Distillation." + // arXiv:1710.06169." } private class Data @@ -122,13 +136,17 @@ private class Data } /// - /// Creates a dataset, an IEnumerable of Data objects, for a GAM sample. Feature1 is a parabola centered around 0, - /// while Feature2 is a simple piecewise function. + /// Creates a dataset, an IEnumerable of Data objects, for a GAM sample. + /// Feature1 is a parabola centered around 0, while Feature2 is a simple + /// piecewise function. /// /// The number of examples to generate. - /// The seed for the random number generator used to produce data. + /// The seed for the random number generator used to + /// produce data. /// - private static IEnumerable GenerateData(int numExamples = 25000, int seed = 1) + private static IEnumerable GenerateData(int numExamples = 25000, + int seed = 1) + { var rng = new Random(seed); float centeredFloat() => (float)(rng.NextDouble() - 0.5); @@ -140,7 +158,8 @@ private static IEnumerable GenerateData(int numExamples = 25000, int seed Features = new float[2] { centeredFloat(), centeredFloat() } }; // Compute the label from the shape functions and add noise. - data.Label = Sigmoid(Parabola(data.Features[0]) + SimplePiecewise(data.Features[1]) + centeredFloat()) > 0.5; + data.Label = Sigmoid(Parabola(data.Features[0]) + + SimplePiecewise(data.Features[1]) + centeredFloat()) > 0.5; yield return data; } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs index e762da494b..07318371f3 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs @@ -10,35 +10,44 @@ 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. + // 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. + // 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(); + 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -48,7 +57,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -74,7 +85,9 @@ public static void Example() // Precision || 0.8583 | 0.8972 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -85,13 +98,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -114,9 +131,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs index 4204f0c4c2..880c170ac5 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs @@ -11,15 +11,17 @@ 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. + // 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. + // 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. @@ -31,23 +33,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.LbfgsLogisticRegression(options); + 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -57,7 +66,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -83,7 +94,9 @@ public static void Example() // Precision || 0.8571 | 0.8902 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -94,13 +107,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -123,9 +140,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs index 4bf27d017a..f50a53bb6a 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs @@ -8,39 +8,49 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class LightGbm { - // This example requires installation of additional nuget package - // Microsoft.ML.LightGbm. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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.LightGbm(); + var pipeline = mlContext.BinaryClassification.Trainers + .LightGbm(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -50,7 +60,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -73,7 +85,9 @@ public static void Example() // Precision || 0.7531 | 0.7860 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -84,13 +98,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -113,9 +131,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.tt index 8bef899d83..2de4012354 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.tt @@ -10,8 +10,9 @@ string LabelThreshold = "0.5f"; string DataSepValue = "0.03f"; string OptionsInclude = ""; string Comments= @" - // This example requires installation of additional nuget package - // Microsoft.ML.LightGbm."; + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/Microsoft.ML.FastTree/"; string ExpectedOutputPerInstance = @"// Expected output: // Label: True, Prediction: True diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs index 82bdace764..dcf8b54116 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs @@ -9,19 +9,22 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class LightGbmWithOptions { - // This example requires installation of additional nuget package - // Microsoft.ML.LightGbm. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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. @@ -35,23 +38,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.LightGbm(options); + var pipeline = mlContext.BinaryClassification.Trainers + .LightGbm(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -61,7 +71,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -84,7 +96,9 @@ public static void Example() // Precision || 0.6563 | 0.7131 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -95,13 +109,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -124,9 +142,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.tt index b193e17b54..3488a6178e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.tt @@ -9,8 +9,9 @@ string LabelThreshold = "0.5f"; string DataSepValue = "0.03f"; string OptionsInclude = "using Microsoft.ML.Trainers.LightGbm;"; string Comments= @" - // This example requires installation of additional nuget package - // Microsoft.ML.LightGbm."; + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/Microsoft.ML.FastTree/"; string TrainerOptions = @"LightGbmBinaryTrainer.Options { diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs index 80c58da58a..8a31cb273a 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs @@ -10,35 +10,44 @@ public static class LinearSvm { 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. + // 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. + // 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.LinearSvm(); + var pipeline = mlContext.BinaryClassification.Trainers + .LinearSvm(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -48,7 +57,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -71,7 +82,9 @@ public static void Example() // Precision || 0.6624 | 0.8387 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -82,13 +95,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -111,9 +128,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs index 293769438b..4b934286bb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs @@ -11,15 +11,17 @@ public static class LinearSvmWithOptions { 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. + // 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. + // 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. @@ -31,23 +33,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.LinearSvm(options); + var pipeline = mlContext.BinaryClassification.Trainers + .LinearSvm(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -57,7 +66,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -80,7 +91,9 @@ public static void Example() // Precision || 0.8044 | 0.9127 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -91,13 +104,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -120,9 +137,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude index ace4bdec1d..dc68e4ac7a 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude @@ -13,28 +13,34 @@ namespace Samples.Dynamic.Trainers.BinaryClassification {<#=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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); - // Convert the list of data points to an IDataView object, which is consumable by ML.NET API. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); <# if (TrainerOptions == null) { #> // Define the trainer. <#=TrainerDescription#> - var pipeline = mlContext.BinaryClassification.Trainers.<#=Trainer#>; + var pipeline = mlContext.BinaryClassification.Trainers + .<#=Trainer#>; + <# } else { #> // Define trainer options. var options = new <#=TrainerOptions#>; // Define the trainer. <#=TrainerDescription#> - var pipeline = mlContext.BinaryClassification.Trainers.<#=Trainer#>(options); + var pipeline = mlContext.BinaryClassification.Trainers + .<#=Trainer#>(options); + <# } #> // Train the model. @@ -44,7 +50,8 @@ namespace Samples.Dynamic.Trainers.BinaryClassification var transformedTrainingData = model.Transform(trainingData); // Measure the quality of the trained model. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTrainingData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -52,14 +59,18 @@ namespace Samples.Dynamic.Trainers.BinaryClassification <#=ExpectedOutput#> // Create prediction function from the trained model. - var engine = mlContext.Model.CreatePredictionEngine(model); + var engine = mlContext.Model + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); - Console.WriteLine($"Actual label: {dataPoint.Label}, predicted label: {result.PredictedLabel}, " + - $"score of being positive class: {result.Score}, and probability of beling positive class: {result.Probability}."); + Console.WriteLine($"Actual label: {dataPoint.Label}, " + + $"predicted label: {result.PredictedLabel}, " + + $"score of being positive class: {result.Score}, " + + $"and probability of beling positive class: " + + $"{result.Probability}."); } <#=ExpectedOutputPerInstance#> @@ -74,7 +85,8 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Label. public bool Label { get; set; } - // Features from the first field. Note that different fields can have different numbers of features. + // Features from the first field. Note that different fields can have + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -87,8 +99,8 @@ namespace Samples.Dynamic.Trainers.BinaryClassification public float[] Field2 { get; set; } } - // This class defines objects produced by trained model. The trained model maps - // a DataPoint to a Result. + // This class defines objects produced by trained model. The trained model + // maps a DataPoint to a Result. public class Result { // Label. @@ -102,13 +114,16 @@ namespace Samples.Dynamic.Trainers.BinaryClassification } // Function used to create toy data sets. - private static IEnumerable GenerateRandomDataPoints(int exampleCount, int seed = 0) + private static IEnumerable GenerateRandomDataPoints( + int exampleCount, int seed = 0) + { var rnd = new Random(seed); var data = new List(); for (int i = 0; i < exampleCount; ++i) { - // Initialize an example with a random label and an empty feature vector. + // Initialize an example with a random label and an empty feature + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -118,9 +133,10 @@ namespace Samples.Dynamic.Trainers.BinaryClassification }; // Fill feature vectors according the assigned label. - // Notice that features from different fields have different biases and therefore different distributions. - // In practices such as game recommendation, one may use one field to store features from user profile and - // another field to store features from game profile. + // Notice that features from different fields have different biases + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -148,14 +164,20 @@ namespace Samples.Dynamic.Trainers.BinaryClassification } // Function used to show evaluation metrics such as accuracy of predictions. - private static void PrintMetrics(CalibratedBinaryClassificationMetrics metrics) + private static void PrintMetrics( + CalibratedBinaryClassificationMetrics metrics) + { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); Console.WriteLine($"Log Loss Reduction: {metrics.LogLossReduction:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PermutationFeatureImportance.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PermutationFeatureImportance.cs index 55d6c54cc4..f8db811758 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PermutationFeatureImportance.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PermutationFeatureImportance.cs @@ -9,8 +9,9 @@ public static class PermutationFeatureImportance { 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. + // 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. var mlContext = new MLContext(seed:1); // Create sample data. @@ -19,12 +20,15 @@ public static void Example() // Load the sample data as an IDataView. var data = mlContext.Data.LoadFromEnumerable(samples); - // Define a training pipeline that concatenates features into a vector, normalizes them, and then - // trains a linear model. - var featureColumns = new string[] { nameof(Data.Feature1), nameof(Data.Feature2) }; - var pipeline = mlContext.Transforms.Concatenate("Features", featureColumns) - .Append(mlContext.Transforms.NormalizeMinMax("Features")) - .Append(mlContext.BinaryClassification.Trainers.SdcaLogisticRegression()); + // Define a training pipeline that concatenates features into a vector, + // normalizes them, and then trains a linear model. + var featureColumns = + new string[] { nameof(Data.Feature1), nameof(Data.Feature2) }; + var pipeline = mlContext.Transforms + .Concatenate("Features", featureColumns) + .Append(mlContext.Transforms.NormalizeMinMax("Features")) + .Append(mlContext.BinaryClassification.Trainers + .SdcaLogisticRegression()); // Fit the pipeline to the data. var model = pipeline.Fit(data); @@ -35,17 +39,22 @@ public static void Example() // Extract the predictor. var linearPredictor = model.LastTransformer; - // Compute the permutation metrics for the linear model using the normalized data. - var permutationMetrics = mlContext.BinaryClassification.PermutationFeatureImportance( - linearPredictor, transformedData, permutationCount: 30); - - // Now let's look at which features are most important to the model overall. - // Get the feature indices sorted by their impact on AUC. - var sortedIndices = permutationMetrics.Select((metrics, index) => new { index, metrics.AreaUnderRocCurve}) - .OrderByDescending(feature => Math.Abs(feature.AreaUnderRocCurve.Mean)) + // Compute the permutation metrics for the linear model using the + // normalized data. + var permutationMetrics = mlContext.BinaryClassification + .PermutationFeatureImportance(linearPredictor, transformedData, + permutationCount: 30); + + // Now let's look at which features are most important to the model + // overall. Get the feature indices sorted by their impact on AUC. + var sortedIndices = permutationMetrics + .Select((metrics, index) => new { index, metrics.AreaUnderRocCurve}) + .OrderByDescending( + feature => Math.Abs(feature.AreaUnderRocCurve.Mean)) .Select(feature => feature.index); - Console.WriteLine("Feature\tModel Weight\tChange in AUC\t95% Confidence in the Mean Change in AUC"); + Console.WriteLine("Feature\tModel Weight\tChange in AUC" + + "\t95% Confidence in the Mean Change in AUC"); var auc = permutationMetrics.Select(x => x.AreaUnderRocCurve).ToArray(); foreach (int i in sortedIndices) { @@ -76,10 +85,14 @@ private class Data /// linear combination of the features. /// /// The number of examples. - /// The bias, or offset, in the calculation of the label. - /// The weight to multiply the first feature with to compute the label. - /// The weight to multiply the second feature with to compute the label. - /// The seed for generating feature values and label noise. + /// The bias, or offset, in the calculation of the label. + /// + /// The weight to multiply the first feature with to + /// compute the label. + /// The weight to multiply the second feature with to + /// compute the label. + /// The seed for generating feature values and label + /// noise. /// An enumerable of Data objects. private static IEnumerable GenerateData(int nExamples = 10000, double bias = 0, double weight1 = 1, double weight2 = 2, int seed = 1) @@ -94,7 +107,9 @@ private static IEnumerable GenerateData(int nExamples = 10000, }; // Create a noisy label. - var value = (float)(bias + weight1 * data.Feature1 + weight2 * data.Feature2 + rng.NextDouble() - 0.5); + var value = (float)(bias + weight1 * data.Feature1 + weight2 * + data.Feature2 + rng.NextDouble() - 0.5); + data.Label = Sigmoid(value) > 0.5; yield return data; } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs index ed9949a6ee..7d8d38820c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs @@ -10,35 +10,44 @@ public static class Prior { 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. + // 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. + // 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.Prior(); + var pipeline = mlContext.BinaryClassification.Trainers + .Prior(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -48,7 +57,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -71,7 +82,9 @@ public static void Example() // Precision || 0.6840 | 0.0000 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -82,13 +95,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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.3f).ToArray() + // 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.3f).ToArray() }; } } - // Example with label and 50 feature values. A data set is a collection of such examples. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -111,9 +128,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs index f3e56fc24f..ddc9db28eb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs @@ -10,41 +10,52 @@ public static class SdcaLogisticRegression { 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. + // 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. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); - // ML.NET doesn't cache data set by default. Therefore, if one reads a data set from a file and accesses it many times, - // it can be slow due to expensive featurization and disk operations. When the considered data can fit into memory, - // a solution is to cache the data in memory. Caching is especially helpful when working with iterative algorithms + // ML.NET doesn't cache data set by default. Therefore, if one reads a + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.SdcaLogisticRegression(); + var pipeline = mlContext.BinaryClassification.Trainers + .SdcaLogisticRegression(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -54,7 +65,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -77,7 +90,9 @@ public static void Example() // Precision || 0.6210 | 0.6667 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -88,13 +103,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -117,9 +136,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs index 8e564fb8e3..744f7a680d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs @@ -11,20 +11,24 @@ public static class SdcaLogisticRegressionWithOptions { 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. + // 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. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); - // ML.NET doesn't cache data set by default. Therefore, if one reads a data set from a file and accesses it many times, - // it can be slow due to expensive featurization and disk operations. When the considered data can fit into memory, - // a solution is to cache the data in memory. Caching is especially helpful when working with iterative algorithms + // ML.NET doesn't cache data set by default. Therefore, if one reads a + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); @@ -40,23 +44,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.SdcaLogisticRegression(options); + var pipeline = mlContext.BinaryClassification.Trainers + .SdcaLogisticRegression(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -66,7 +77,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -89,7 +102,9 @@ public static void Example() // Precision || 0.5957 | 0.6726 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -100,13 +115,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -129,9 +148,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs index 5127c84b28..8a8b008a15 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs @@ -10,41 +10,52 @@ public static class SdcaNonCalibrated { 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. + // 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. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); - // ML.NET doesn't cache data set by default. Therefore, if one reads a data set from a file and accesses it many times, - // it can be slow due to expensive featurization and disk operations. When the considered data can fit into memory, - // a solution is to cache the data in memory. Caching is especially helpful when working with iterative algorithms + // ML.NET doesn't cache data set by default. Therefore, if one reads a + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.SdcaNonCalibrated(); + var pipeline = mlContext.BinaryClassification.Trainers + .SdcaNonCalibrated(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -54,7 +65,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -76,7 +89,9 @@ public static void Example() // Precision || 0.6185 | 0.6653 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -87,13 +102,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -116,9 +135,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs index 6d55a0286e..3f6b478845 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs @@ -11,20 +11,24 @@ public static class SdcaNonCalibratedWithOptions { 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. + // 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. + // Convert the list of data points to an IDataView object, which is + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); - // ML.NET doesn't cache data set by default. Therefore, if one reads a data set from a file and accesses it many times, - // it can be slow due to expensive featurization and disk operations. When the considered data can fit into memory, - // a solution is to cache the data in memory. Caching is especially helpful when working with iterative algorithms + // ML.NET doesn't cache data set by default. Therefore, if one reads a + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); @@ -42,23 +46,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.SdcaNonCalibrated(options); + var pipeline = mlContext.BinaryClassification.Trainers + .SdcaNonCalibrated(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -68,7 +79,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -91,7 +104,9 @@ public static void Example() // Precision || 0.5705 | 0.6809 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -102,13 +117,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -131,9 +150,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs index 5eb6a3c947..88b2272551 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs @@ -10,35 +10,44 @@ public static class SgdCalibrated { 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. + // 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. + // 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.SgdCalibrated(); + var pipeline = mlContext.BinaryClassification.Trainers + .SgdCalibrated(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -48,7 +57,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -71,7 +82,9 @@ public static void Example() // Precision || 0.6417 | 0.5763 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -82,13 +95,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -111,9 +128,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs index bbd7772ec4..b5c7319da0 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs @@ -11,15 +11,17 @@ public static class SgdCalibratedWithOptions { 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. + // 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. + // 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. @@ -34,23 +36,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.SgdCalibrated(options); + var pipeline = mlContext.BinaryClassification.Trainers + .SgdCalibrated(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -60,7 +69,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -83,7 +94,9 @@ public static void Example() // Precision || 0.5412 | 0.6625 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -94,13 +107,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -123,9 +140,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs index 91cee50153..5a905588dc 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs @@ -10,35 +10,44 @@ public static class SgdNonCalibrated { 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. + // 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. + // 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.SgdNonCalibrated(); + var pipeline = mlContext.BinaryClassification.Trainers + .SgdNonCalibrated(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -48,7 +57,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -71,7 +82,9 @@ public static void Example() // Precision || 0.6441 | 0.5759 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -82,13 +95,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -111,9 +128,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs index 5509e6f426..581f9c3d2e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs @@ -11,15 +11,17 @@ public static class SgdNonCalibratedWithOptions { 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. + // 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. + // 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. @@ -31,23 +33,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.SgdNonCalibrated(options); + var pipeline = mlContext.BinaryClassification.Trainers + .SgdNonCalibrated(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -57,7 +66,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.EvaluateNonCalibrated(transformedTestData); + var metrics = mlContext.BinaryClassification + .EvaluateNonCalibrated(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -80,7 +91,9 @@ public static void Example() // Precision || 0.5373 | 0.5878 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -91,13 +104,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -120,9 +137,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs index 243d99cccc..78ec9d1316 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs @@ -8,39 +8,49 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class SymbolicSgdLogisticRegression { - // This example requires installation of additional NuGet package - // Microsoft.ML.Mkl.Components. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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.SymbolicSgdLogisticRegression(); + var pipeline = mlContext.BinaryClassification.Trainers + .SymbolicSgdLogisticRegression(); + // 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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -50,7 +60,9 @@ public static void Example() // Label: False, Prediction: True // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -73,7 +85,9 @@ public static void Example() // Precision || 0.8235 | 0.8397 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -84,13 +98,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -113,9 +131,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.tt index 8374d8c301..71f4e6ed66 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.tt @@ -10,8 +10,9 @@ string LabelThreshold = "0.5f"; string DataSepValue = "0.1f"; string OptionsInclude = ""; string Comments = @" - // This example requires installation of additional NuGet package - // Microsoft.ML.Mkl.Components."; + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/Microsoft.ML.FastTree/"; string ExpectedOutputPerInstance = @"// Expected output: // Label: True, Prediction: False diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs index c8d179e617..6edf2f4872 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs @@ -9,19 +9,22 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class SymbolicSgdLogisticRegressionWithOptions { - // This example requires installation of additional NuGet package - // Microsoft.ML.Mkl.Components. + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // 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. @@ -33,23 +36,30 @@ public static void Example() }; // Define the trainer. - var pipeline = mlContext.BinaryClassification.Trainers.SymbolicSgdLogisticRegression(options); + var pipeline = mlContext.BinaryClassification.Trainers + .SymbolicSgdLogisticRegression(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)); + // 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(); + var predictions = mlContext.Data + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) - Console.WriteLine($"Label: {p.Label}, Prediction: {p.PredictedLabel}"); + Console.WriteLine($"Label: {p.Label}, " + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -59,7 +69,9 @@ public static void Example() // Label: False, Prediction: False // Evaluate the overall metrics. - var metrics = mlContext.BinaryClassification.Evaluate(transformedTestData); + var metrics = mlContext.BinaryClassification + .Evaluate(transformedTestData); + PrintMetrics(metrics); // Expected output: @@ -82,7 +94,9 @@ public static void Example() // Precision || 0.7964 | 0.6847 | } - private static IEnumerable GenerateRandomDataPoints(int count, int seed=0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed=0) + { var random = new Random(seed); float randomFloat() => (float)random.NextDouble(); @@ -93,13 +107,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se { 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() + // 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. + // Example with label and 50 feature values. A data set is a collection of + // such examples. private class DataPoint { public bool Label { get; set; } @@ -122,9 +140,13 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}"); + Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") + ; + Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}"); + Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") + ; + Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.tt index c1b3ccd0e4..51bb6d0515 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.tt @@ -9,8 +9,9 @@ string LabelThreshold = "0.5f"; string DataSepValue = "0.1f"; string OptionsInclude = "using Microsoft.ML.Trainers;"; string Comments = @" - // This example requires installation of additional NuGet package - // Microsoft.ML.Mkl.Components."; + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/Microsoft.ML.FastTree/"; string TrainerOptions = @"SymbolicSgdLogisticRegressionBinaryTrainer.Options() { 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 fa37323b89..6d350ccf11 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude @@ -4,6 +4,7 @@ string LabelThreshold = "0.5f"; string DataSepValue = "0.03f"; string OptionsInclude = "using Microsoft.ML.Trainers.FastTree;"; string Comments= @" - // This example requires installation of additional NuGet package - // Microsoft.ML.FastTree."; + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/Microsoft.ML.FastTree/"; #> \ No newline at end of file diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index 5b318ae9e3..0e1beb9cc4 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using Samples.Dynamic; +using Samples.Dynamic.Trainers.BinaryClassification; namespace Microsoft.ML.Samples { @@ -14,8 +15,10 @@ internal static void RunAll() foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { var sample = type.GetMethod("Example", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); + String[] test = {"PairwiseCoupling", "PermutationFeatureImportance", "SdcaMaximumEntropy", + "SdcaMaximumEntropyWithOptions", "SdcaNonCalibrated", "SdcaNonCalibratedWithOptions"}; + if (sample != null && Array.IndexOf(test, type.Name) > -1)//type.Name.Equals("ConvertType")) - if (sample != null) { Console.WriteLine(type.Name); sample.Invoke(null, null); From 7abb9d1287a621079e7b99657f13a8bc26c65b1a Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:29:45 -0700 Subject: [PATCH 02/60] Update AveragedPerceptron.cs fixing spacing --- .../AveragedPerceptron.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs index 56ae8ce9ff..fdf8a6d41c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs @@ -11,43 +11,43 @@ public static class AveragedPerceptron 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .AveragedPerceptron(); + .AveragedPerceptron(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,10 +96,10 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() }; } } From 5c3214baa57324d5cb273b43a209570cfae172a4 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:31:52 -0700 Subject: [PATCH 03/60] Update AveragedPerceptronWithOptions.cs fixing whitespace --- .../AveragedPerceptronWithOptions.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs index 5c3a2b16fc..edc99f85e9 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs @@ -12,16 +12,16 @@ public static class AveragedPerceptronWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -36,29 +36,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .AveragedPerceptron(options); + .AveragedPerceptron(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -69,7 +69,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -94,7 +94,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -107,16 +107,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -140,11 +140,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 74935ee00fef18a2ad7318f8c6e3c4d72eb0b29c Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:32:23 -0700 Subject: [PATCH 04/60] Update AveragedPerceptron.cs --- .../Trainers/BinaryClassification/AveragedPerceptron.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs index fdf8a6d41c..9f465545b3 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs @@ -129,11 +129,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From e9891f9ca801bf31a96c50e4adc04d2cdc9b6f28 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:32:54 -0700 Subject: [PATCH 05/60] Update AveragedPerceptron.cs --- .../Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs index 9f465545b3..18bd191d8b 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs @@ -105,7 +105,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } From c9dcd03efdbc9e1dfa22dd16c61c63d9db9b84a6 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:35:26 -0700 Subject: [PATCH 06/60] Update BinaryClassification.ttinclude fixing whitespace --- .../BinaryClassification.ttinclude | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude index 8501738bd2..134c0f9973 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude @@ -14,24 +14,24 @@ namespace Samples.Dynamic.Trainers.BinaryClassification 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); <# if (CacheData) { #> // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); <# } #> @@ -39,7 +39,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification <# if (TrainerOptions == null) { #> // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>(); + .<#=Trainer#>(); <# } else { #> // Define trainer options. @@ -47,7 +47,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>(options); + .<#=Trainer#>(options); <# } #> @@ -55,30 +55,30 @@ namespace Samples.Dynamic.Trainers.BinaryClassification var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); <#=ExpectedOutputPerInstance#> <# string Evaluator = IsCalibrated ? "Evaluate" : - "EvaluateNonCalibrated"; #> + "EvaluateNonCalibrated"; #> // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .<#=Evaluator#>(transformedTestData); + .<#=Evaluator#>(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,16 +99,16 @@ namespace Samples.Dynamic.Trainers.BinaryClassification 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - <#=DataSepValue#>).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + <#=DataSepValue#>).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -132,14 +132,14 @@ namespace Samples.Dynamic.Trainers.BinaryClassification Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } -} \ No newline at end of file +} From 384f9838b131fb8e55ae21af857d474869ae4f8f Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:38:44 -0700 Subject: [PATCH 07/60] Update FactorizationMachine.cs fixing whitespace --- .../FactorizationMachine.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs index 8c3ba88dc0..aab8caac32 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs @@ -11,51 +11,51 @@ public static class FactorizationMachine 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FieldAwareFactorizationMachine(); + .FieldAwareFactorizationMachine(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -66,7 +66,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -91,7 +91,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -104,16 +104,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -137,11 +137,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 885f8208c5bd2edf6e9df6ff594fbcb81db3c2fc Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:41:08 -0700 Subject: [PATCH 08/60] Update FastForest.cs fixing whitespace --- .../BinaryClassification/FastForest.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs index 16187c6cc7..5fc35bfb05 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs @@ -14,43 +14,43 @@ public static class FastForest 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastForest(); + .FastForest(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,16 +99,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -132,11 +132,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 1d1679b20a7f8435c1c869727e459b965072646d Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:43:04 -0700 Subject: [PATCH 09/60] Update FastForestWithOptions.cs fixing whitespace --- .../FastForestWithOptions.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs index 5a84f95799..f3eb8b673e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs @@ -15,16 +15,16 @@ public static class FastForestWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -40,29 +40,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastForest(options); + .FastForest(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -73,7 +73,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -98,7 +98,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -111,16 +111,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -144,11 +144,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From f3ec594f9687a0db2bddcd71a83fc491a183471b Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:44:57 -0700 Subject: [PATCH 10/60] Update FastTree.cs fixing whitespace --- .../Trainers/BinaryClassification/FastTree.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs index b3585bd5d9..d9cd9b46b5 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs @@ -14,43 +14,43 @@ public static class 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastTree(); + .FastTree(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -89,7 +89,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -102,16 +102,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -135,11 +135,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From fb62ed5ab96079a6c00fde836637962f49f97478 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:48:44 -0700 Subject: [PATCH 11/60] Update FastTreeWithOptions.cs fixing whitespace --- .../FastTreeWithOptions.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs index 5587f6c4dd..5146394ccb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs @@ -15,16 +15,16 @@ public static class FastTreeWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -40,29 +40,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastTree(options); + .FastTree(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -73,7 +73,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -101,7 +101,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -114,16 +114,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -147,11 +147,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From c243e2e0a4dc6c2552d508ff5a8250dfa2b3c3c4 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:56:01 -0700 Subject: [PATCH 12/60] Update FieldAwareFactorizationMachine.cs fixing whitespace --- .../FieldAwareFactorizationMachine.cs | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs index 0a5c281f58..62134bae34 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs @@ -9,35 +9,36 @@ namespace Samples.Dynamic.Trainers.BinaryClassification public static class FieldAwareFactorizationMachine { // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction. 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); // Convert the list of data points to an IDataView object, which is - // consumable by ML.NET API. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); // Define the trainer. // This trainer trains field-aware factorization (FFM) - //for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET. + // for binary classification. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET. var pipeline = mlContext.BinaryClassification.Trainers - .FieldAwareFactorizationMachine( + .FieldAwareFactorizationMachine( + // Specify three feature columns! new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), - nameof(DataPoint.Field2) }, + nameof(DataPoint.Field2) }, // Specify binary label's column name. nameof(DataPoint.Label) ); @@ -51,7 +52,7 @@ public static void Example() // Measure the quality of the trained model. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTrainingData); + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -80,17 +81,17 @@ public static void Example() // Create prediction function from the trained model. var engine = mlContext.Model - .CreatePredictionEngine(model); + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); Console.WriteLine($"Actual label: {dataPoint.Label}, " - + $"predicted label: {result.PredictedLabel}, " + + $"predicted label: {result.PredictedLabel}, " + $"score of being positive class: {result.Score}, " - + $"and probability of beling positive class: " - + $"{result.Probability}."); + + $"and probability of beling positive class: " + + $"{result.Probability}."); } // Expected output: @@ -111,7 +112,7 @@ private class DataPoint public bool Label { get; set; } // Features from the first field. Note that different fields can have - // different numbers of features. + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -125,7 +126,7 @@ private class DataPoint } // This class defines objects produced by trained model. The trained model - // maps a DataPoint to a Result. + // maps a DataPoint to a Result. public class Result { // Label. @@ -140,7 +141,7 @@ public class Result // Function used to create toy data sets. private static IEnumerable GenerateRandomDataPoints( - int exampleCount, int seed = 0) + int exampleCount, int seed = 0) { var rnd = new Random(seed); @@ -148,7 +149,7 @@ private static IEnumerable GenerateRandomDataPoints( for (int i = 0; i < exampleCount; ++i) { // Initialize an example with a random label and an empty feature - // vector. + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -159,9 +160,9 @@ private static IEnumerable GenerateRandomDataPoints( // Fill feature vectors according the assigned label. // Notice that features from different fields have different biases - // and therefore different distributions. In practices such as game - // recommendation, one may use one field to store features from user - // profile and another field to store features from game profile. + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -197,11 +198,11 @@ private static void PrintMetrics( Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); From 5458e79caf5e343e8d5fba54b78ab5ce2305361d Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 19:58:36 -0700 Subject: [PATCH 13/60] Update FieldAwareFactorizationMachine.cs --- .../BinaryClassification/FieldAwareFactorizationMachine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs index 62134bae34..4701c1a2f9 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs @@ -191,7 +191,7 @@ private static IEnumerable GenerateRandomDataPoints( // Function used to show evaluation metrics such as accuracy of predictions. private static void PrintMetrics( - CalibratedBinaryClassificationMetrics metrics) + CalibratedBinaryClassificationMetrics metrics) { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); From 60130f3a6b4e11cdc233f395cb91deb92e060ca8 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:00:59 -0700 Subject: [PATCH 14/60] Update FieldAwareFactorizationMachine.tt fixing whitespace --- .../FieldAwareFactorizationMachine.tt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt index d3b1a1086b..94445c085f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt @@ -4,7 +4,7 @@ string ClassName="FieldAwareFactorizationMachine"; string Trainer = @"FieldAwareFactorizationMachine( // Specify three feature columns! new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), - nameof(DataPoint.Field2) }, + nameof(DataPoint.Field2) }, // Specify binary label's column name. nameof(DataPoint.Label) )"; @@ -13,15 +13,15 @@ string OptionsInclude = null; string Comments = @" // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction."; string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) //for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET."; + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET."; string TrainerOptions = null; From edcb4f56da5c093f6f3a709ea89fee125510195c Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:03:52 -0700 Subject: [PATCH 15/60] Update FieldAwareFactorizationMachineWithOptions.cs fixing whitespace --- ...eldAwareFactorizationMachineWithOptions.cs | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs index f68fd8abce..bf67c6b163 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs @@ -10,21 +10,21 @@ namespace Samples.Dynamic.Trainers.BinaryClassification public static class FieldAwareFactorizationMachineWithOptions { // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction. 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); // Convert the list of data points to an IDataView object, which is - // consumable by ML.NET API. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); // Define trainer options. @@ -32,7 +32,7 @@ public static void Example() { FeatureColumnName = nameof(DataPoint.Field0), ExtraFeatureColumns = - new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, @@ -45,12 +45,12 @@ public static void Example() // Define the trainer. // This trainer trains field-aware factorization (FFM) // for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET. var pipeline = mlContext.BinaryClassification.Trainers - .FieldAwareFactorizationMachine(options); + .FieldAwareFactorizationMachine(options); // Train the model. @@ -61,7 +61,7 @@ public static void Example() // Measure the quality of the trained model. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTrainingData); + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -90,17 +90,18 @@ public static void Example() // Create prediction function from the trained model. var engine = mlContext.Model - .CreatePredictionEngine(model); + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); Console.WriteLine($"Actual label: {dataPoint.Label}, " - + $"predicted label: {result.PredictedLabel}, " + + $"predicted label: {result.PredictedLabel}, " + $"score of being positive class: {result.Score}, " - + $"and probability of beling positive class: " - + $"{result.Probability}."); + + $"and probability of beling positive class: " + + $"{result.Probability}."); + } // Expected output: @@ -121,7 +122,7 @@ private class DataPoint public bool Label { get; set; } // Features from the first field. Note that different fields can have - // different numbers of features. + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -135,7 +136,7 @@ private class DataPoint } // This class defines objects produced by trained model. The trained model - // maps a DataPoint to a Result. + // maps a DataPoint to a Result. public class Result { // Label. @@ -150,7 +151,7 @@ public class Result // Function used to create toy data sets. private static IEnumerable GenerateRandomDataPoints( - int exampleCount, int seed = 0) + int exampleCount, int seed = 0) { var rnd = new Random(seed); @@ -158,7 +159,7 @@ private static IEnumerable GenerateRandomDataPoints( for (int i = 0; i < exampleCount; ++i) { // Initialize an example with a random label and an empty feature - // vector. + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -169,9 +170,9 @@ private static IEnumerable GenerateRandomDataPoints( // Fill feature vectors according the assigned label. // Notice that features from different fields have different biases - // and therefore different distributions. In practices such as game - // recommendation, one may use one field to store features from user - // profile and another field to store features from game profile. + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -200,18 +201,18 @@ private static IEnumerable GenerateRandomDataPoints( // Function used to show evaluation metrics such as accuracy of predictions. private static void PrintMetrics( - CalibratedBinaryClassificationMetrics metrics) + CalibratedBinaryClassificationMetrics metrics) { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); From 3d8613eef9a0e799ec79aca5ccf96072c6ab0b34 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:04:23 -0700 Subject: [PATCH 16/60] Update FieldAwareFactorizationMachine.cs --- .../BinaryClassification/FieldAwareFactorizationMachine.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs index 4701c1a2f9..cd77a6278c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs @@ -92,6 +92,7 @@ public static void Example() + $"score of being positive class: {result.Score}, " + $"and probability of beling positive class: " + $"{result.Probability}."); + } // Expected output: From 5aabe0e87ab9ba5f85d0fd24dabd7bfe0b947d5d Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:05:28 -0700 Subject: [PATCH 17/60] Update FieldAwareFactorizationMachineWithOptions.tt fixing whitespace --- .../FieldAwareFactorizationMachineWithOptions.tt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt index fafc98de1e..69c15d2af6 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt @@ -7,21 +7,21 @@ string OptionsInclude = @"using Microsoft.ML.Trainers;"; string Comments = @" // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction."; string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) // for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET."; + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET."; string TrainerOptions = @"FieldAwareFactorizationMachineTrainer.Options { FeatureColumnName = nameof(DataPoint.Field0), ExtraFeatureColumns = - new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, From 85036e2b2c0e893fbf1ea930b803604ce7966ed4 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:08:19 -0700 Subject: [PATCH 18/60] Update LbfgsLogisticRegression.cs fixing whitespace --- .../LbfgsLogisticRegression.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs index 07318371f3..d6946953a7 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs @@ -11,43 +11,43 @@ 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LbfgsLogisticRegression(); + .LbfgsLogisticRegression(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,16 +99,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -132,11 +132,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 92c6c194bc769698e637885d625f90533a4f33fb Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:10:26 -0700 Subject: [PATCH 19/60] Update LbfgsLogisticRegressionWithOptions.cs fixing whitespace --- .../LbfgsLogisticRegressionWithOptions.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs index 880c170ac5..906835ed10 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs @@ -12,16 +12,16 @@ 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -34,29 +34,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LbfgsLogisticRegression(options); + .LbfgsLogisticRegression(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -67,7 +67,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -95,7 +95,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -108,16 +108,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -141,11 +141,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From f0990a1a81420d39c98962ab9e304a17b331c892 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:15:17 -0700 Subject: [PATCH 20/60] Update LightGbm.cs fixing whitespace --- .../Trainers/BinaryClassification/LightGbm.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs index f50a53bb6a..57b33c9355 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs @@ -14,43 +14,43 @@ public static class LightGbm 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LightGbm(); + .LightGbm(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,10 +99,10 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } @@ -132,11 +132,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 672b785ae1e908a1dfdb2eaaee8aa89607650531 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:17:23 -0700 Subject: [PATCH 21/60] Update LightGbmWithOptions.cs fixing whitespace --- .../LightGbmWithOptions.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs index dcf8b54116..58831de014 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs @@ -15,16 +15,16 @@ public static class LightGbmWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -39,29 +39,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LightGbm(options); + .LightGbm(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -72,7 +72,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -97,7 +97,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -110,16 +110,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -143,11 +143,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From c41905d9abe1fa75f0a021a878327fa369e977da Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:19:37 -0700 Subject: [PATCH 22/60] Update LinearSvm.cs fixing whitespace --- .../BinaryClassification/LinearSvm.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs index 8a31cb273a..bf3356d80d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs @@ -11,43 +11,43 @@ public static class LinearSvm 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LinearSvm(); + .LinearSvm(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,16 +96,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -129,11 +129,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From e93c6993777d5f2816f59a2da33e3fd5ddb75742 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:22:22 -0700 Subject: [PATCH 23/60] Update LinearSvmWithOptions.cs fixing whitespace --- .../LinearSvmWithOptions.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs index 4b934286bb..48ae80208b 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs @@ -12,16 +12,16 @@ public static class LinearSvmWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -34,29 +34,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LinearSvm(options); + .LinearSvm(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -67,7 +67,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -92,7 +92,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -105,10 +105,10 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() }; } } @@ -138,11 +138,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From cbbee590e8faa0086f3713063f97ef504e6277bc Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:24:34 -0700 Subject: [PATCH 24/60] Update MultipleFeatureColumnsBinaryClassification.ttinclude fixing whitespace --- ...atureColumnsBinaryClassification.ttinclude | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude index dc68e4ac7a..84045b487d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude @@ -14,23 +14,23 @@ namespace Samples.Dynamic.Trainers.BinaryClassification 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); // Convert the list of data points to an IDataView object, which is - // consumable by ML.NET API. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); <# if (TrainerOptions == null) { #> // Define the trainer. <#=TrainerDescription#> var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>; + .<#=Trainer#>; <# } else { #> // Define trainer options. @@ -39,7 +39,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Define the trainer. <#=TrainerDescription#> var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>(options); + .<#=Trainer#>(options); <# } #> @@ -51,7 +51,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Measure the quality of the trained model. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTrainingData); + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -60,17 +60,17 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Create prediction function from the trained model. var engine = mlContext.Model - .CreatePredictionEngine(model); + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); Console.WriteLine($"Actual label: {dataPoint.Label}, " - + $"predicted label: {result.PredictedLabel}, " + + $"predicted label: {result.PredictedLabel}, " + $"score of being positive class: {result.Score}, " - + $"and probability of beling positive class: " - + $"{result.Probability}."); + + $"and probability of beling positive class: " + + $"{result.Probability}."); } <#=ExpectedOutputPerInstance#> @@ -86,7 +86,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification public bool Label { get; set; } // Features from the first field. Note that different fields can have - // different numbers of features. + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -100,7 +100,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification } // This class defines objects produced by trained model. The trained model - // maps a DataPoint to a Result. + // maps a DataPoint to a Result. public class Result { // Label. @@ -115,7 +115,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Function used to create toy data sets. private static IEnumerable GenerateRandomDataPoints( - int exampleCount, int seed = 0) + int exampleCount, int seed = 0) { var rnd = new Random(seed); @@ -123,7 +123,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification for (int i = 0; i < exampleCount; ++i) { // Initialize an example with a random label and an empty feature - // vector. + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -134,9 +134,9 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Fill feature vectors according the assigned label. // Notice that features from different fields have different biases - // and therefore different distributions. In practices such as game - // recommendation, one may use one field to store features from user - // profile and another field to store features from game profile. + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -165,18 +165,18 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Function used to show evaluation metrics such as accuracy of predictions. private static void PrintMetrics( - CalibratedBinaryClassificationMetrics metrics) + CalibratedBinaryClassificationMetrics metrics) { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); From 2fc5e20b3d1850376d109be4803596a0027d2725 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:26:35 -0700 Subject: [PATCH 25/60] Update PriorTrainer.cs fixing whitespace --- .../BinaryClassification/PriorTrainer.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs index 7d8d38820c..28da363d94 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs @@ -11,43 +11,43 @@ public static class Prior 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .Prior(); + .Prior(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,16 +96,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.3f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.3f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -129,11 +130,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From a43123c3098c4a89fd99d98f7edfe0783aa5f006 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:27:54 -0700 Subject: [PATCH 26/60] Update AveragedPerceptron.cs --- .../Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs index 18bd191d8b..a38dab19ed 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs @@ -100,6 +100,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; } } From 58484e2c2850ac32b7aaddc8871c45365cf6d2fa Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:28:23 -0700 Subject: [PATCH 27/60] Update AveragedPerceptronWithOptions.cs --- .../BinaryClassification/AveragedPerceptronWithOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs index edc99f85e9..b9d6df1675 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs @@ -111,6 +111,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; } } From a42c2e8e716dc2a58f499b28428cf9dc87c02349 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:28:49 -0700 Subject: [PATCH 28/60] Update BinaryClassification.ttinclude --- .../Trainers/BinaryClassification/BinaryClassification.ttinclude | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude index 134c0f9973..f86241fd6c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude @@ -103,6 +103,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + <#=DataSepValue#>).ToArray() + }; } } From a9afb7277b272e19dce90b98fd16f7026e682ce3 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:31:18 -0700 Subject: [PATCH 29/60] Update FactorizationMachine.cs --- .../Trainers/BinaryClassification/FactorizationMachine.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs index aab8caac32..94160008bb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs @@ -108,6 +108,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; } } From e780b0d458a2a75b37de08d42ae7a4f1c57d197a Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:32:45 -0700 Subject: [PATCH 30/60] Update FastForestWithOptions.cs --- .../Trainers/BinaryClassification/FastForestWithOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs index f3eb8b673e..18536b97da 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs @@ -115,6 +115,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From 617a5c51fffa8bea4e66cd360f5e5730844c88b2 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:33:33 -0700 Subject: [PATCH 31/60] Update FastTree.cs --- .../Dynamic/Trainers/BinaryClassification/FastTree.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs index d9cd9b46b5..016ae02154 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs @@ -106,6 +106,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From f95144b9fe56198ab245eba57ad9da63342bdef6 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:34:07 -0700 Subject: [PATCH 32/60] Update FastTreeWithOptions.cs --- .../Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs index 5146394ccb..55f608a5dd 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs @@ -118,6 +118,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From ff86eca01d356567d5ffb7aad7257a592fe5a534 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:36:53 -0700 Subject: [PATCH 33/60] Update LbfgsLogisticRegression.cs --- .../Trainers/BinaryClassification/LbfgsLogisticRegression.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs index d6946953a7..91f293850f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs @@ -103,6 +103,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; } } From 5b7734e235f573faa0f9ab011a13491306e8129c Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:37:31 -0700 Subject: [PATCH 34/60] Update LbfgsLogisticRegressionWithOptions.cs --- .../BinaryClassification/LbfgsLogisticRegressionWithOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs index 906835ed10..83ad0553a6 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs @@ -112,6 +112,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; } } From b0c0813d8c8da3cb99882ea37c5be260942a01ef Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:38:15 -0700 Subject: [PATCH 35/60] Update LightGbm.cs --- .../Dynamic/Trainers/BinaryClassification/LightGbm.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs index 57b33c9355..bc35c1e3ab 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs @@ -103,6 +103,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From 92d564de2f109673344166efaaa4457c0edd82cb Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:38:48 -0700 Subject: [PATCH 36/60] Update LightGbmWithOptions.cs --- .../Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs index 58831de014..7848ec5f90 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs @@ -114,6 +114,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From 061a83a1920e05f06053338cf58ea30b6a58a442 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:39:30 -0700 Subject: [PATCH 37/60] Update LinearSvm.cs --- .../Dynamic/Trainers/BinaryClassification/LinearSvm.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs index bf3356d80d..07a4a26f91 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs @@ -100,6 +100,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; } } From 0402c9052941e7eb888c92dd37aa3f8bb03b5920 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:40:02 -0700 Subject: [PATCH 38/60] Update LinearSvmWithOptions.cs --- .../Trainers/BinaryClassification/LinearSvmWithOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs index 48ae80208b..71436d8090 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs @@ -109,6 +109,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.1f).ToArray() + }; } } From 5c28cf6e7fd80e2f4be64ad81709294218483d24 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:43:15 -0700 Subject: [PATCH 39/60] Update SdcaLogisticRegression.cs --- .../SdcaLogisticRegression.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs index ddc9db28eb..6e7bf2fd9d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs @@ -11,51 +11,51 @@ public static class SdcaLogisticRegression 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaLogisticRegression(); + .SdcaLogisticRegression(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -66,7 +66,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -91,7 +91,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -104,16 +104,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -137,11 +137,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From d39a4a2b43a40c3f8395c1fbdd7e1182b8a05efe Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:45:27 -0700 Subject: [PATCH 40/60] Update SdcaLogisticRegressionWithOptions.cs --- .../SdcaLogisticRegressionWithOptions.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs index 744f7a680d..794e447152 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs @@ -12,23 +12,23 @@ public static class SdcaLogisticRegressionWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); @@ -45,29 +45,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaLogisticRegression(options); + .SdcaLogisticRegression(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -78,7 +78,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -103,7 +103,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -116,16 +116,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -149,11 +149,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From fef50feeaa5ab62e067f783cf36f946a82ea6360 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:47:51 -0700 Subject: [PATCH 41/60] Update SdcaNonCalibrated.cs --- .../BinaryClassification/SdcaNonCalibrated.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs index 8a8b008a15..40ece543c6 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs @@ -11,51 +11,51 @@ public static class SdcaNonCalibrated 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaNonCalibrated(); + .SdcaNonCalibrated(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -66,7 +66,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -90,7 +90,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -103,16 +103,16 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -136,11 +136,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From deac2b10e4f1ac15020120f1d3226ca2dd8e86ee Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:49:54 -0700 Subject: [PATCH 42/60] Update SdcaNonCalibratedWithOptions.cs --- .../SdcaNonCalibratedWithOptions.cs | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs index 3f6b478845..ebf6908148 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs @@ -12,23 +12,23 @@ public static class SdcaNonCalibratedWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); @@ -47,29 +47,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaNonCalibrated(options); + .SdcaNonCalibrated(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -80,7 +80,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -105,7 +105,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -118,10 +118,11 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } @@ -151,11 +152,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From a808724d1c2629b611ed2e3503c4142258d48e4e Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:50:27 -0700 Subject: [PATCH 43/60] Update SdcaNonCalibrated.cs --- .../Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs index 40ece543c6..b70056ef2a 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs @@ -107,6 +107,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From 31f95e3185dfe8cfefbaaa61dc777b095df5243e Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:50:51 -0700 Subject: [PATCH 44/60] Update SdcaLogisticRegressionWithOptions.cs --- .../BinaryClassification/SdcaLogisticRegressionWithOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs index 794e447152..ed6976fd66 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs @@ -120,6 +120,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From 1b05112037a32885bd7830033d740b7e0dbca220 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:51:21 -0700 Subject: [PATCH 45/60] Update SdcaLogisticRegression.cs --- .../Trainers/BinaryClassification/SdcaLogisticRegression.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs index 6e7bf2fd9d..ac829b5e9e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs @@ -108,6 +108,7 @@ private static IEnumerable GenerateRandomDataPoints(int count, Features = Enumerable.Repeat(label, 50) .Select(x => x ? randomFloat() : randomFloat() + 0.03f).ToArray() + }; } } From 47481ed7b56d9a37a44753e466d0c8aeba3c9c7e Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:53:58 -0700 Subject: [PATCH 46/60] Update SgdCalibrated.cs --- .../BinaryClassification/SgdCalibrated.cs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs index 88b2272551..bee2184975 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs @@ -11,43 +11,42 @@ public static class SgdCalibrated 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdCalibrated(); - + .SgdCalibrated(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -58,7 +57,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -83,7 +82,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,16 +95,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -129,11 +129,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 371e043bab7d09a04e37e89c6c387dca1ed036c4 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:55:49 -0700 Subject: [PATCH 47/60] Update SgdCalibratedWithOptions.cs --- .../SgdCalibratedWithOptions.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs index b5c7319da0..07b5eb3bcf 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs @@ -12,16 +12,16 @@ public static class SgdCalibratedWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -37,29 +37,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdCalibrated(options); + .SgdCalibrated(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -70,7 +70,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -95,7 +95,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -108,16 +108,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -141,11 +142,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 254fdef2a3ed9f9d956d79c2e1b537748158e0e3 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:57:46 -0700 Subject: [PATCH 48/60] Update SgdNonCalibrated.cs --- .../BinaryClassification/SgdNonCalibrated.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs index 5a905588dc..3f7a296947 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs @@ -11,43 +11,43 @@ public static class SgdNonCalibrated 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdNonCalibrated(); + .SgdNonCalibrated(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,16 +96,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -129,11 +130,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From b860f308bacd164ff685a94550e99b60d550b6a7 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 20:59:34 -0700 Subject: [PATCH 49/60] Update SgdNonCalibratedWithOptions.cs --- .../SgdNonCalibratedWithOptions.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs index 581f9c3d2e..c93cc98959 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs @@ -12,16 +12,16 @@ public static class SgdNonCalibratedWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -34,29 +34,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdNonCalibrated(options); + .SgdNonCalibrated(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -67,7 +67,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -92,7 +92,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -105,16 +105,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -138,11 +139,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 664aa71fcbc281ceaa6a9f8feb19d2669f630aa8 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:01:14 -0700 Subject: [PATCH 50/60] Update SymbolicSgdLogisticRegression.cs --- .../SymbolicSgdLogisticRegression.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs index 78ec9d1316..f6f365fc1d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs @@ -14,43 +14,43 @@ public static class SymbolicSgdLogisticRegression 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SymbolicSgdLogisticRegression(); + .SymbolicSgdLogisticRegression(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,16 +99,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -132,11 +133,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From f6871c8eb8f96af61533a8ad6110564ecca9890f Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:04:25 -0700 Subject: [PATCH 51/60] Update SymbolicSgdLogisticRegressionWithOptions.cs --- ...ymbolicSgdLogisticRegressionWithOptions.cs | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs index 6edf2f4872..ed3ea4f498 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs @@ -15,16 +15,16 @@ public static class SymbolicSgdLogisticRegressionWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -37,29 +37,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SymbolicSgdLogisticRegression(options); + .SymbolicSgdLogisticRegression(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -70,7 +70,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -95,7 +95,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -108,16 +108,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -141,11 +142,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 539fe7495acde469696369eb8c960eea58fea4a5 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:07:10 -0700 Subject: [PATCH 52/60] Update Program.cs changing back --- docs/samples/Microsoft.ML.Samples/Program.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index 0e1beb9cc4..1b49fbc2ef 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -15,10 +15,8 @@ internal static void RunAll() foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { var sample = type.GetMethod("Example", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); - String[] test = {"PairwiseCoupling", "PermutationFeatureImportance", "SdcaMaximumEntropy", - "SdcaMaximumEntropyWithOptions", "SdcaNonCalibrated", "SdcaNonCalibratedWithOptions"}; - if (sample != null && Array.IndexOf(test, type.Name) > -1)//type.Name.Equals("ConvertType")) + if (sample != null) { Console.WriteLine(type.Name); sample.Invoke(null, null); From ed513480c87fca97804fb678d45902971f9a5e6d Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:07:43 -0700 Subject: [PATCH 53/60] Update Program.cs --- docs/samples/Microsoft.ML.Samples/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index 1b49fbc2ef..4c46399421 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -1,7 +1,6 @@ -using System; +using System; using System.Reflection; using Samples.Dynamic; -using Samples.Dynamic.Trainers.BinaryClassification; namespace Microsoft.ML.Samples { From d1129450453706551dc71ac75b2618366bc2fc62 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:08:42 -0700 Subject: [PATCH 54/60] Update Program.cs From 3af17a8be3c5e36078c54ffb567e21a724c6026f Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:10:21 -0700 Subject: [PATCH 55/60] Update Program.cs --- docs/samples/Microsoft.ML.Samples/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index 4c46399421..d3e1a5f9c8 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -1,6 +1,5 @@ using System; using System.Reflection; -using Samples.Dynamic; namespace Microsoft.ML.Samples { @@ -10,6 +9,7 @@ public static class Program internal static void RunAll() { + // Samples counter. int samples = 0; foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { From 93a98febb571718c6d7a9ea300af95f74c216a2c Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:11:33 -0700 Subject: [PATCH 56/60] Update Program.cs --- docs/samples/Microsoft.ML.Samples/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index d3e1a5f9c8..b472817179 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using Samples.Dynamic; namespace Microsoft.ML.Samples { @@ -9,13 +10,12 @@ public static class Program internal static void RunAll() { - // Samples counter. int samples = 0; foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { var sample = type.GetMethod("Example", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); - - if (sample != null) + + { Console.WriteLine(type.Name); sample.Invoke(null, null); From 652f39e75058a6468bff3fbe21cee04baa59266a Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Mon, 1 Jul 2019 21:12:14 -0700 Subject: [PATCH 57/60] Update Program.cs --- docs/samples/Microsoft.ML.Samples/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index b472817179..4c46399421 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -14,8 +14,8 @@ internal static void RunAll() foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { var sample = type.GetMethod("Example", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); - - + + if (sample != null) { Console.WriteLine(type.Name); sample.Invoke(null, null); From 0857a130437cce24902c67f4b742c397d4106364 Mon Sep 17 00:00:00 2001 From: sierralee51 <36902786+sierralee51@users.noreply.github.com> Date: Tue, 2 Jul 2019 11:17:12 -0700 Subject: [PATCH 58/60] fixed tab issues --- .../AveragedPerceptron.cs | 37 +++++++------ .../AveragedPerceptronWithOptions.cs | 39 ++++++------- .../BinaryClassification.ttinclude | 48 ++++++++-------- .../FactorizationMachine.cs | 47 ++++++++-------- .../BinaryClassification/FastForest.cs | 44 ++++++++------- .../FastForestWithOptions.cs | 45 +++++++-------- .../Trainers/BinaryClassification/FastTree.cs | 45 +++++++-------- .../FastTreeWithOptions.cs | 45 +++++++-------- .../FieldAwareFactorizationMachine.cs | 55 +++++++++---------- .../FieldAwareFactorizationMachine.tt | 14 ++--- ...eldAwareFactorizationMachineWithOptions.cs | 54 +++++++++--------- ...eldAwareFactorizationMachineWithOptions.tt | 12 ++-- .../LbfgsLogisticRegression.cs | 39 ++++++------- .../LbfgsLogisticRegressionWithOptions.cs | 37 +++++++------ .../Trainers/BinaryClassification/LightGbm.cs | 39 ++++++------- .../LightGbmWithOptions.cs | 39 ++++++------- .../BinaryClassification/LinearSvm.cs | 39 ++++++------- .../LinearSvmWithOptions.cs | 39 ++++++------- ...atureColumnsBinaryClassification.ttinclude | 43 ++++++++------- .../BinaryClassification/PriorTrainer.cs | 39 ++++++------- .../SdcaLogisticRegression.cs | 47 ++++++++-------- .../SdcaLogisticRegressionWithOptions.cs | 47 ++++++++-------- .../BinaryClassification/SdcaNonCalibrated.cs | 47 ++++++++-------- .../SdcaNonCalibratedWithOptions.cs | 47 ++++++++-------- .../BinaryClassification/SgdCalibrated.cs | 38 +++++++------ .../SgdCalibratedWithOptions.cs | 39 ++++++------- .../BinaryClassification/SgdNonCalibrated.cs | 39 ++++++------- .../SgdNonCalibratedWithOptions.cs | 37 +++++++------ .../SymbolicSgdLogisticRegression.cs | 39 ++++++------- ...ymbolicSgdLogisticRegressionWithOptions.cs | 37 +++++++------ .../TreeSamplesTemplate.ttinclude | 6 +- 31 files changed, 624 insertions(+), 598 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs index a38dab19ed..d4b331f3fa 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs @@ -11,16 +11,16 @@ public static class AveragedPerceptron 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. @@ -32,22 +32,22 @@ public static void Example() var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,17 +96,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -130,14 +130,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs index b9d6df1675..c87ee5f0c0 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs @@ -12,16 +12,16 @@ public static class AveragedPerceptronWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -36,29 +36,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .AveragedPerceptron(options); + .AveragedPerceptron(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -69,7 +69,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -94,7 +94,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -107,17 +107,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -141,14 +141,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude index f86241fd6c..da379c097e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude @@ -14,8 +14,8 @@ namespace Samples.Dynamic.Trainers.BinaryClassification 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 + // 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); @@ -23,15 +23,15 @@ namespace Samples.Dynamic.Trainers.BinaryClassification var dataPoints = GenerateRandomDataPoints(1000); // Convert the list of data points to an IDataView object, which is - // consumable by ML.NET API. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); <# if (CacheData) { #> // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); <# } #> @@ -39,7 +39,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification <# if (TrainerOptions == null) { #> // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>(); + .<#=Trainer#>(); <# } else { #> // Define trainer options. @@ -47,7 +47,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>(options); + .<#=Trainer#>(options); <# } #> @@ -55,30 +55,30 @@ namespace Samples.Dynamic.Trainers.BinaryClassification var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); <#=ExpectedOutputPerInstance#> <# string Evaluator = IsCalibrated ? "Evaluate" : - "EvaluateNonCalibrated"; #> + "EvaluateNonCalibrated"; #> // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .<#=Evaluator#>(transformedTestData); + .<#=Evaluator#>(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,17 +99,17 @@ namespace Samples.Dynamic.Trainers.BinaryClassification 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - <#=DataSepValue#>).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + <#=DataSepValue#>).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -133,11 +133,11 @@ namespace Samples.Dynamic.Trainers.BinaryClassification Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs index 94160008bb..baaff28ce5 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs @@ -11,51 +11,51 @@ public static class FactorizationMachine 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FieldAwareFactorizationMachine(); + .FieldAwareFactorizationMachine(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -66,7 +66,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -91,7 +91,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -104,17 +104,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -138,14 +138,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs index 5fc35bfb05..8169c74925 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs @@ -8,49 +8,49 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastForest { - // This example requires installation of additional NuGet package for - // Microsoft.ML.FastTree at - // https://www.nuget.org/packages/Microsoft.ML.FastTree/ + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastForest(); + .FastForest(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,16 +99,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -132,11 +133,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); @@ -144,3 +145,4 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs index 18536b97da..7c084d129a 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs @@ -9,22 +9,22 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastForestWithOptions { - // This example requires installation of additional NuGet package for - // Microsoft.ML.FastTree at - // https://www.nuget.org/packages/Microsoft.ML.FastTree/ + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -40,29 +40,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastForest(options); + .FastForest(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -73,7 +73,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -98,7 +98,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -111,17 +111,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -145,11 +145,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); @@ -157,3 +157,4 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs index 016ae02154..69a900be9f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs @@ -8,49 +8,49 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastTree { - // This example requires installation of additional NuGet package for - // Microsoft.ML.FastTree at - // https://www.nuget.org/packages/Microsoft.ML.FastTree/ + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastTree(); + .FastTree(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -89,7 +89,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -102,17 +102,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -136,11 +136,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); @@ -148,3 +148,4 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs index 55f608a5dd..80c8900179 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs @@ -9,22 +9,22 @@ namespace Samples.Dynamic.Trainers.BinaryClassification { public static class FastTreeWithOptions { - // This example requires installation of additional NuGet package for - // Microsoft.ML.FastTree at - // https://www.nuget.org/packages/Microsoft.ML.FastTree/ + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -40,29 +40,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .FastTree(options); + .FastTree(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -73,7 +73,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -101,7 +101,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -114,17 +114,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -148,11 +148,11 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); @@ -160,3 +160,4 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs index cd77a6278c..0eea904fc2 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs @@ -9,36 +9,35 @@ namespace Samples.Dynamic.Trainers.BinaryClassification public static class FieldAwareFactorizationMachine { // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction. 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); // Convert the list of data points to an IDataView object, which is - // consumable by ML.NET API. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); // Define the trainer. // This trainer trains field-aware factorization (FFM) // for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET. var pipeline = mlContext.BinaryClassification.Trainers - .FieldAwareFactorizationMachine( - + .FieldAwareFactorizationMachine( // Specify three feature columns! new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), - nameof(DataPoint.Field2) }, + nameof(DataPoint.Field2) }, // Specify binary label's column name. nameof(DataPoint.Label) ); @@ -52,7 +51,7 @@ public static void Example() // Measure the quality of the trained model. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTrainingData); + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -81,18 +80,18 @@ public static void Example() // Create prediction function from the trained model. var engine = mlContext.Model - .CreatePredictionEngine(model); + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); Console.WriteLine($"Actual label: {dataPoint.Label}, " - + $"predicted label: {result.PredictedLabel}, " + + $"predicted label: {result.PredictedLabel}, " + $"score of being positive class: {result.Score}, " - + $"and probability of beling positive class: " - + $"{result.Probability}."); - + + $"and probability of beling positive class: " + + $"{result.Probability}."); + } // Expected output: @@ -113,7 +112,7 @@ private class DataPoint public bool Label { get; set; } // Features from the first field. Note that different fields can have - // different numbers of features. + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -127,7 +126,7 @@ private class DataPoint } // This class defines objects produced by trained model. The trained model - // maps a DataPoint to a Result. + // maps a DataPoint to a Result. public class Result { // Label. @@ -142,7 +141,7 @@ public class Result // Function used to create toy data sets. private static IEnumerable GenerateRandomDataPoints( - int exampleCount, int seed = 0) + int exampleCount, int seed = 0) { var rnd = new Random(seed); @@ -150,7 +149,7 @@ private static IEnumerable GenerateRandomDataPoints( for (int i = 0; i < exampleCount; ++i) { // Initialize an example with a random label and an empty feature - // vector. + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -161,9 +160,9 @@ private static IEnumerable GenerateRandomDataPoints( // Fill feature vectors according the assigned label. // Notice that features from different fields have different biases - // and therefore different distributions. In practices such as game - // recommendation, one may use one field to store features from user - // profile and another field to store features from game profile. + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -192,18 +191,18 @@ private static IEnumerable GenerateRandomDataPoints( // Function used to show evaluation metrics such as accuracy of predictions. private static void PrintMetrics( - CalibratedBinaryClassificationMetrics metrics) + CalibratedBinaryClassificationMetrics metrics) { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt index 94445c085f..25aaa92d4c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt @@ -4,7 +4,7 @@ string ClassName="FieldAwareFactorizationMachine"; string Trainer = @"FieldAwareFactorizationMachine( // Specify three feature columns! new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), - nameof(DataPoint.Field2) }, + nameof(DataPoint.Field2) }, // Specify binary label's column name. nameof(DataPoint.Label) )"; @@ -13,15 +13,15 @@ string OptionsInclude = null; string Comments = @" // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction."; string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) - //for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET."; + // for binary classification. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET."; string TrainerOptions = null; diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs index bf67c6b163..72ab26be84 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs @@ -10,21 +10,21 @@ namespace Samples.Dynamic.Trainers.BinaryClassification public static class FieldAwareFactorizationMachineWithOptions { // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction. 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); // Convert the list of data points to an IDataView object, which is - // consumable by ML.NET API. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); // Define trainer options. @@ -32,7 +32,7 @@ public static void Example() { FeatureColumnName = nameof(DataPoint.Field0), ExtraFeatureColumns = - new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, @@ -45,12 +45,12 @@ public static void Example() // Define the trainer. // This trainer trains field-aware factorization (FFM) // for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET. + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET. var pipeline = mlContext.BinaryClassification.Trainers - .FieldAwareFactorizationMachine(options); + .FieldAwareFactorizationMachine(options); // Train the model. @@ -61,7 +61,7 @@ public static void Example() // Measure the quality of the trained model. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTrainingData); + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -90,18 +90,18 @@ public static void Example() // Create prediction function from the trained model. var engine = mlContext.Model - .CreatePredictionEngine(model); + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); Console.WriteLine($"Actual label: {dataPoint.Label}, " - + $"predicted label: {result.PredictedLabel}, " + + $"predicted label: {result.PredictedLabel}, " + $"score of being positive class: {result.Score}, " - + $"and probability of beling positive class: " - + $"{result.Probability}."); - + + $"and probability of beling positive class: " + + $"{result.Probability}."); + } // Expected output: @@ -122,7 +122,7 @@ private class DataPoint public bool Label { get; set; } // Features from the first field. Note that different fields can have - // different numbers of features. + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -136,7 +136,7 @@ private class DataPoint } // This class defines objects produced by trained model. The trained model - // maps a DataPoint to a Result. + // maps a DataPoint to a Result. public class Result { // Label. @@ -151,7 +151,7 @@ public class Result // Function used to create toy data sets. private static IEnumerable GenerateRandomDataPoints( - int exampleCount, int seed = 0) + int exampleCount, int seed = 0) { var rnd = new Random(seed); @@ -159,7 +159,7 @@ private static IEnumerable GenerateRandomDataPoints( for (int i = 0; i < exampleCount; ++i) { // Initialize an example with a random label and an empty feature - // vector. + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -170,9 +170,9 @@ private static IEnumerable GenerateRandomDataPoints( // Fill feature vectors according the assigned label. // Notice that features from different fields have different biases - // and therefore different distributions. In practices such as game - // recommendation, one may use one field to store features from user - // profile and another field to store features from game profile. + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -201,18 +201,18 @@ private static IEnumerable GenerateRandomDataPoints( // Function used to show evaluation metrics such as accuracy of predictions. private static void PrintMetrics( - CalibratedBinaryClassificationMetrics metrics) + CalibratedBinaryClassificationMetrics metrics) { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt index 69c15d2af6..b4fd91e8fc 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt @@ -7,21 +7,21 @@ string OptionsInclude = @"using Microsoft.ML.Trainers;"; string Comments = @" // This example first train a field-aware factorization to binary - // classification, measure the trained model's quality, and finally + // classification, measure the trained model's quality, and finally // use the trained model to make prediction."; string TrainerDescription = @"// This trainer trains field-aware factorization (FFM) // for binary classification. - // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory - // behind and - // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the - // training algorithm implemented in ML.NET."; + // See https://www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf for the theory + // behind and + // https://github.com/wschin/fast-ffm/blob/master/fast-ffm.pdf for the + // training algorithm implemented in ML.NET."; string TrainerOptions = @"FieldAwareFactorizationMachineTrainer.Options { FeatureColumnName = nameof(DataPoint.Field0), ExtraFeatureColumns = - new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs index 91f293850f..28a44ab95b 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs @@ -11,43 +11,43 @@ 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LbfgsLogisticRegression(); + .LbfgsLogisticRegression(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,17 +99,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -133,14 +133,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs index 83ad0553a6..06347e81fa 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs @@ -12,16 +12,16 @@ 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -41,22 +41,22 @@ public static void Example() var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -67,7 +67,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -95,7 +95,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -108,17 +108,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -142,14 +142,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs index bc35c1e3ab..41e003a7d5 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs @@ -14,43 +14,43 @@ public static class LightGbm 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LightGbm(); + .LightGbm(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,17 +99,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -133,14 +133,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs index 7848ec5f90..8654e31db0 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs @@ -15,16 +15,16 @@ public static class LightGbmWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -39,29 +39,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LightGbm(options); + .LightGbm(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -72,7 +72,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -97,7 +97,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -110,17 +110,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -144,14 +144,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs index 07a4a26f91..b1449a86fb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs @@ -11,43 +11,43 @@ public static class LinearSvm 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LinearSvm(); + .LinearSvm(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,17 +96,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -130,14 +130,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs index 71436d8090..2f3b5c928f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs @@ -12,16 +12,16 @@ public static class LinearSvmWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -34,29 +34,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LinearSvm(options); + .LinearSvm(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -67,7 +67,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -92,7 +92,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -105,17 +105,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -139,14 +139,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude index 84045b487d..f44fce4b9d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude @@ -14,23 +14,23 @@ namespace Samples.Dynamic.Trainers.BinaryClassification 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. + // 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. IEnumerable data = GenerateRandomDataPoints(500); // Convert the list of data points to an IDataView object, which is - // consumable by ML.NET API. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(data); <# if (TrainerOptions == null) { #> // Define the trainer. <#=TrainerDescription#> var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>; + .<#=Trainer#>; <# } else { #> // Define trainer options. @@ -39,7 +39,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Define the trainer. <#=TrainerDescription#> var pipeline = mlContext.BinaryClassification.Trainers - .<#=Trainer#>(options); + .<#=Trainer#>(options); <# } #> @@ -51,7 +51,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Measure the quality of the trained model. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTrainingData); + .Evaluate(transformedTrainingData); // Show the quality metrics. PrintMetrics(metrics); @@ -60,17 +60,18 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Create prediction function from the trained model. var engine = mlContext.Model - .CreatePredictionEngine(model); + .CreatePredictionEngine(model); // Make some predictions. foreach(var dataPoint in data.Take(5)) { var result = engine.Predict(dataPoint); Console.WriteLine($"Actual label: {dataPoint.Label}, " - + $"predicted label: {result.PredictedLabel}, " + + $"predicted label: {result.PredictedLabel}, " + $"score of being positive class: {result.Score}, " - + $"and probability of beling positive class: " - + $"{result.Probability}."); + + $"and probability of beling positive class: " + + $"{result.Probability}."); + } <#=ExpectedOutputPerInstance#> @@ -86,7 +87,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification public bool Label { get; set; } // Features from the first field. Note that different fields can have - // different numbers of features. + // different numbers of features. [VectorType(featureLength)] public float[] Field0 { get; set; } @@ -100,7 +101,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification } // This class defines objects produced by trained model. The trained model - // maps a DataPoint to a Result. + // maps a DataPoint to a Result. public class Result { // Label. @@ -115,7 +116,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Function used to create toy data sets. private static IEnumerable GenerateRandomDataPoints( - int exampleCount, int seed = 0) + int exampleCount, int seed = 0) { var rnd = new Random(seed); @@ -123,7 +124,7 @@ namespace Samples.Dynamic.Trainers.BinaryClassification for (int i = 0; i < exampleCount; ++i) { // Initialize an example with a random label and an empty feature - // vector. + // vector. var sample = new DataPoint() { Label = rnd.Next() % 2 == 0, @@ -134,9 +135,9 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Fill feature vectors according the assigned label. // Notice that features from different fields have different biases - // and therefore different distributions. In practices such as game - // recommendation, one may use one field to store features from user - // profile and another field to store features from game profile. + // and therefore different distributions. In practices such as game + // recommendation, one may use one field to store features from user + // profile and another field to store features from game profile. for (int j = 0; j < featureLength; ++j) { var value0 = (float)rnd.NextDouble(); @@ -165,18 +166,18 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Function used to show evaluation metrics such as accuracy of predictions. private static void PrintMetrics( - CalibratedBinaryClassificationMetrics metrics) + CalibratedBinaryClassificationMetrics metrics) { Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs index 28da363d94..2c29637478 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs @@ -11,43 +11,43 @@ public static class Prior 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .Prior(); + .Prior(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,17 +96,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.3f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.3f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -130,14 +130,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs index ac829b5e9e..57c37a2b8f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs @@ -11,51 +11,51 @@ public static class SdcaLogisticRegression 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaLogisticRegression(); + .SdcaLogisticRegression(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -66,7 +66,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -91,7 +91,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -104,17 +104,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -138,14 +138,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs index ed6976fd66..8a8ddc6ea3 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs @@ -12,23 +12,23 @@ public static class SdcaLogisticRegressionWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); @@ -45,29 +45,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaLogisticRegression(options); + .SdcaLogisticRegression(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -78,7 +78,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -103,7 +103,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -116,17 +116,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -150,14 +150,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs index b70056ef2a..a84a4088e2 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs @@ -11,51 +11,51 @@ public static class SdcaNonCalibrated 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaNonCalibrated(); + .SdcaNonCalibrated(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: True @@ -66,7 +66,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -90,7 +90,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -103,17 +103,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -137,14 +137,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs index ebf6908148..15c7682046 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs @@ -12,23 +12,23 @@ public static class SdcaNonCalibratedWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // ML.NET doesn't cache data set by default. Therefore, if one reads a - // data set from a file and accesses it many times, it can be slow due - // to expensive featurization and disk operations. When the considered - // data can fit into memory, a solution is to cache the data in memory. - // Caching is especially helpful when working with iterative algorithms + // data set from a file and accesses it many times, it can be slow due + // to expensive featurization and disk operations. When the considered + // data can fit into memory, a solution is to cache the data in memory. + // Caching is especially helpful when working with iterative algorithms // which needs many data passes. trainingData = mlContext.Data.Cache(trainingData); @@ -47,29 +47,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SdcaNonCalibrated(options); + .SdcaNonCalibrated(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -80,7 +80,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -105,7 +105,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -118,17 +118,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -152,14 +152,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs index bee2184975..ed3329ddbe 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs @@ -11,42 +11,43 @@ public static class SgdCalibrated 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers .SgdCalibrated(); + // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -57,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -82,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -95,17 +96,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -129,14 +130,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs index 07b5eb3bcf..9cdabf802a 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs @@ -12,16 +12,16 @@ public static class SgdCalibratedWithOptions 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -37,29 +37,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdCalibrated(options); + .SgdCalibrated(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -70,7 +70,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -95,7 +95,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -108,17 +108,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -142,14 +142,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs index 3f7a296947..cac2f011a6 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs @@ -11,43 +11,43 @@ public static class SgdNonCalibrated 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdNonCalibrated(); + .SgdNonCalibrated(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -58,7 +58,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -83,7 +83,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -96,17 +96,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -130,14 +130,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs index c93cc98959..1dc3926244 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs @@ -12,16 +12,16 @@ public static class SgdNonCalibratedWithOptions 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 + // 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -34,29 +34,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdNonCalibrated(options); + .SgdNonCalibrated(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -67,7 +67,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .EvaluateNonCalibrated(transformedTestData); + .EvaluateNonCalibrated(transformedTestData); PrintMetrics(metrics); @@ -92,7 +92,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -105,17 +105,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.03f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.03f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -139,14 +139,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs index f6f365fc1d..6e2216498f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs @@ -14,43 +14,43 @@ public static class SymbolicSgdLogisticRegression 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SymbolicSgdLogisticRegression(); + .SymbolicSgdLogisticRegression(); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -61,7 +61,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -86,7 +86,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -99,17 +99,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -133,14 +133,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs index ed3ea4f498..f011387e1c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs @@ -15,16 +15,16 @@ public static class SymbolicSgdLogisticRegressionWithOptions 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 + // 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. + // 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. + // consumable by ML.NET API. var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints); // Define trainer options. @@ -37,29 +37,29 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SymbolicSgdLogisticRegression(options); + .SymbolicSgdLogisticRegression(options); // Train the model. var model = pipeline.Fit(trainingData); // Create testing data. Use different random seed to make it different - // from training data. + // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .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(); + .CreateEnumerable(transformedTestData, + reuseRowObject: false).ToList(); // Print 5 predictions. foreach (var p in predictions.Take(5)) Console.WriteLine($"Label: {p.Label}, " - + $"Prediction: {p.PredictedLabel}"); + + $"Prediction: {p.PredictedLabel}"); // Expected output: // Label: True, Prediction: False @@ -70,7 +70,7 @@ public static void Example() // Evaluate the overall metrics. var metrics = mlContext.BinaryClassification - .Evaluate(transformedTestData); + .Evaluate(transformedTestData); PrintMetrics(metrics); @@ -95,7 +95,7 @@ public static void Example() } private static IEnumerable GenerateRandomDataPoints(int count, - int seed=0) + int seed=0) { var random = new Random(seed); @@ -108,17 +108,17 @@ private static IEnumerable GenerateRandomDataPoints(int count, 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. + // slightly increased by adding a constant. Features = Enumerable.Repeat(label, 50) - .Select(x => x ? randomFloat() : randomFloat() + - 0.1f).ToArray() - + .Select(x => x ? randomFloat() : randomFloat() + + 0.1f).ToArray() + }; } } // Example with label and 50 feature values. A data set is a collection of - // such examples. + // such examples. private class DataPoint { public bool Label { get; set; } @@ -142,14 +142,15 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + ; Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + ; Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); } } } + 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 6d350ccf11..4cda1fc808 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/TreeSamplesTemplate.ttinclude @@ -4,7 +4,7 @@ string LabelThreshold = "0.5f"; string DataSepValue = "0.03f"; string OptionsInclude = "using Microsoft.ML.Trainers.FastTree;"; string Comments= @" - // This example requires installation of additional NuGet package for - // Microsoft.ML.FastTree at - // https://www.nuget.org/packages/Microsoft.ML.FastTree/"; + // This example requires installation of additional NuGet package for + // Microsoft.ML.FastTree at + // https://www.nuget.org/packages/Microsoft.ML.FastTree/"; #> \ No newline at end of file From 6eac51a55ac70bca936e46a386143f53d99b658c Mon Sep 17 00:00:00 2001 From: sierralee51 <36902786+sierralee51@users.noreply.github.com> Date: Tue, 2 Jul 2019 14:22:20 -0700 Subject: [PATCH 59/60] fixed indentations --- .../BinaryClassification/AveragedPerceptron.cs | 11 +++++------ .../AveragedPerceptronWithOptions.cs | 9 ++++----- .../BinaryClassification.ttinclude | 10 ++++------ .../BinaryClassification/FactorizationMachine.cs | 9 ++++----- .../Trainers/BinaryClassification/FastForest.cs | 9 ++++----- .../BinaryClassification/FastForestWithOptions.cs | 9 ++++----- .../Trainers/BinaryClassification/FastTree.cs | 9 ++++----- .../BinaryClassification/FastTreeWithOptions.cs | 9 ++++----- .../FieldAwareFactorizationMachine.cs | 4 +--- .../FieldAwareFactorizationMachine.tt | 3 +-- .../FieldAwareFactorizationMachineWithOptions.cs | 1 - .../BinaryClassification/LbfgsLogisticRegression.cs | 9 ++++----- .../LbfgsLogisticRegressionWithOptions.cs | 9 ++++----- .../Trainers/BinaryClassification/LightGbm.cs | 13 ++++++------- .../BinaryClassification/LightGbmWithOptions.cs | 9 ++++----- .../Trainers/BinaryClassification/LinearSvm.cs | 9 ++++----- .../BinaryClassification/LinearSvmWithOptions.cs | 9 ++++----- ...ipleFeatureColumnsBinaryClassification.ttinclude | 2 -- .../Trainers/BinaryClassification/PriorTrainer.cs | 9 ++++----- .../BinaryClassification/SdcaLogisticRegression.cs | 9 ++++----- .../SdcaLogisticRegressionWithOptions.cs | 9 ++++----- .../BinaryClassification/SdcaNonCalibrated.cs | 9 ++++----- .../SdcaNonCalibratedWithOptions.cs | 9 ++++----- .../Trainers/BinaryClassification/SgdCalibrated.cs | 9 ++++----- .../SgdCalibratedWithOptions.cs | 9 ++++----- .../BinaryClassification/SgdNonCalibrated.cs | 13 ++++++------- .../SgdNonCalibratedWithOptions.cs | 13 ++++++------- .../SymbolicSgdLogisticRegression.cs | 9 ++++----- .../SymbolicSgdLogisticRegressionWithOptions.cs | 9 ++++----- 29 files changed, 109 insertions(+), 141 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs index d4b331f3fa..fd24a32b39 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptron.cs @@ -27,14 +27,13 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .AveragedPerceptron(); - // 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)); + .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); // Run the model on test data set. var transformedTestData = model.Transform(testData); @@ -129,12 +128,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs index c87ee5f0c0..8f31f474e4 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/AveragedPerceptronWithOptions.cs @@ -38,7 +38,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .AveragedPerceptron(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -140,12 +139,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude index da379c097e..72dc7cc111 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/BinaryClassification.ttinclude @@ -40,7 +40,6 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers .<#=Trainer#>(); - <# } else { #> // Define trainer options. var options = new <#=TrainerOptions#>; @@ -48,7 +47,6 @@ namespace Samples.Dynamic.Trainers.BinaryClassification // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers .<#=Trainer#>(options); - <# } #> // Train the model. @@ -132,12 +130,12 @@ namespace Samples.Dynamic.Trainers.BinaryClassification Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs index baaff28ce5..4e8bec4f4e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FactorizationMachine.cs @@ -35,7 +35,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .FieldAwareFactorizationMachine(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -137,12 +136,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs index 8169c74925..f33feb7063 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForest.cs @@ -30,7 +30,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .FastForest(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -132,12 +131,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs index 7c084d129a..c5bf4d5366 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastForestWithOptions.cs @@ -42,7 +42,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .FastForest(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -144,12 +143,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs index 69a900be9f..f50b8f9732 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTree.cs @@ -30,7 +30,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .FastTree(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -135,12 +134,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs index 80c8900179..87e894d903 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FastTreeWithOptions.cs @@ -42,7 +42,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .FastTree(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -147,12 +146,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs index 0eea904fc2..ab82035837 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs @@ -37,12 +37,10 @@ public static void Example() .FieldAwareFactorizationMachine( // Specify three feature columns! new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), - nameof(DataPoint.Field2) }, - + nameof(DataPoint.Field2) }, // Specify binary label's column name. nameof(DataPoint.Label) ); - // Train the model. var model = pipeline.Fit(trainingData); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt index 25aaa92d4c..22cdd45721 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.tt @@ -4,8 +4,7 @@ string ClassName="FieldAwareFactorizationMachine"; string Trainer = @"FieldAwareFactorizationMachine( // Specify three feature columns! new[] {nameof(DataPoint.Field0), nameof(DataPoint.Field1), - nameof(DataPoint.Field2) }, - + nameof(DataPoint.Field2) }, // Specify binary label's column name. nameof(DataPoint.Label) )"; diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs index 72ab26be84..e601a1a9e8 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs @@ -52,7 +52,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .FieldAwareFactorizationMachine(options); - // Train the model. var model = pipeline.Fit(trainingData); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs index 28a44ab95b..5aece5a264 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegression.cs @@ -27,7 +27,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .LbfgsLogisticRegression(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -132,12 +131,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs index 06347e81fa..fe2fcb14ab 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LbfgsLogisticRegressionWithOptions.cs @@ -36,7 +36,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .LbfgsLogisticRegression(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -141,12 +140,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs index 41e003a7d5..c89a4b2b2c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbm.cs @@ -28,8 +28,7 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .LightGbm(); - + .LightGbm(); // Train the model. var model = pipeline.Fit(trainingData); @@ -37,7 +36,7 @@ public static void Example() // Create testing data. Use different random seed to make it different // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); // Run the model on test data set. var transformedTestData = model.Transform(testData); @@ -132,12 +131,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs index 8654e31db0..5df0a59ee5 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LightGbmWithOptions.cs @@ -41,7 +41,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .LightGbm(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -143,12 +142,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs index b1449a86fb..f47279c331 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvm.cs @@ -27,7 +27,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .LinearSvm(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -129,12 +128,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs index 2f3b5c928f..857ac93439 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/LinearSvmWithOptions.cs @@ -36,7 +36,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .LinearSvm(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -138,12 +137,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude index f44fce4b9d..43358c3441 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude @@ -31,7 +31,6 @@ namespace Samples.Dynamic.Trainers.BinaryClassification <#=TrainerDescription#> var pipeline = mlContext.BinaryClassification.Trainers .<#=Trainer#>; - <# } else { #> // Define trainer options. var options = new <#=TrainerOptions#>; @@ -40,7 +39,6 @@ namespace Samples.Dynamic.Trainers.BinaryClassification <#=TrainerDescription#> var pipeline = mlContext.BinaryClassification.Trainers .<#=Trainer#>(options); - <# } #> // Train the model. diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs index 2c29637478..be54597f13 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/PriorTrainer.cs @@ -27,7 +27,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .Prior(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -129,12 +128,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs index 57c37a2b8f..521c6e671f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegression.cs @@ -35,7 +35,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SdcaLogisticRegression(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -137,12 +136,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs index 8a8ddc6ea3..9ef70a2193 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaLogisticRegressionWithOptions.cs @@ -47,7 +47,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SdcaLogisticRegression(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -149,12 +148,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs index a84a4088e2..73107bb4d7 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibrated.cs @@ -35,7 +35,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SdcaNonCalibrated(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -136,12 +135,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs index 15c7682046..f08d65eed1 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SdcaNonCalibratedWithOptions.cs @@ -49,7 +49,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SdcaNonCalibrated(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -151,12 +150,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs index ed3329ddbe..dcc28ad25c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibrated.cs @@ -27,7 +27,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SgdCalibrated(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -129,12 +128,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs index 9cdabf802a..eea72de60a 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdCalibratedWithOptions.cs @@ -39,7 +39,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SgdCalibrated(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -141,12 +140,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs index cac2f011a6..e55f8d2d65 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibrated.cs @@ -25,8 +25,7 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdNonCalibrated(); - + .SgdNonCalibrated(); // Train the model. var model = pipeline.Fit(trainingData); @@ -34,7 +33,7 @@ public static void Example() // Create testing data. Use different random seed to make it different // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); // Run the model on test data set. var transformedTestData = model.Transform(testData); @@ -129,12 +128,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs index 1dc3926244..1729433565 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SgdNonCalibratedWithOptions.cs @@ -34,8 +34,7 @@ public static void Example() // Define the trainer. var pipeline = mlContext.BinaryClassification.Trainers - .SgdNonCalibrated(options); - + .SgdNonCalibrated(options); // Train the model. var model = pipeline.Fit(trainingData); @@ -43,7 +42,7 @@ public static void Example() // Create testing data. Use different random seed to make it different // from training data. var testData = mlContext.Data - .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); + .LoadFromEnumerable(GenerateRandomDataPoints(500, seed:123)); // Run the model on test data set. var transformedTestData = model.Transform(testData); @@ -138,12 +137,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs index 6e2216498f..172199df0c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegression.cs @@ -30,7 +30,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SymbolicSgdLogisticRegression(); - // Train the model. var model = pipeline.Fit(trainingData); @@ -132,12 +131,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs index f011387e1c..a68fadc8c8 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/SymbolicSgdLogisticRegressionWithOptions.cs @@ -39,7 +39,6 @@ public static void Example() var pipeline = mlContext.BinaryClassification.Trainers .SymbolicSgdLogisticRegression(options); - // Train the model. var model = pipeline.Fit(trainingData); @@ -141,12 +140,12 @@ private static void PrintMetrics(BinaryClassificationMetrics metrics) Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n"); Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable()); From 109a4cda22896b1f66e668a448b7772eb8acfdac Mon Sep 17 00:00:00 2001 From: sierralee51 <36902786+sierralee51@users.noreply.github.com> Date: Tue, 2 Jul 2019 17:03:38 -0700 Subject: [PATCH 60/60] fixed commented-on parts --- .../FieldAwareFactorizationMachine.cs | 8 ++++---- .../FieldAwareFactorizationMachineWithOptions.cs | 10 +++++----- .../FieldAwareFactorizationMachineWithOptions.tt | 2 +- .../Trainers/BinaryClassification/GamWithOptions.cs | 4 ++-- ...ultipleFeatureColumnsBinaryClassification.ttinclude | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs index ab82035837..bddc926ccf 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachine.cs @@ -195,12 +195,12 @@ private static void PrintMetrics( Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs index e601a1a9e8..08b48a9e74 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.cs @@ -32,7 +32,7 @@ public static void Example() { FeatureColumnName = nameof(DataPoint.Field0), ExtraFeatureColumns = - new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, @@ -206,12 +206,12 @@ private static void PrintMetrics( Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}"); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt index b4fd91e8fc..0c7e32048d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/FieldAwareFactorizationMachineWithOptions.tt @@ -21,7 +21,7 @@ string TrainerOptions = @"FieldAwareFactorizationMachineTrainer.Options { FeatureColumnName = nameof(DataPoint.Field0), ExtraFeatureColumns = - new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, + new[] { nameof(DataPoint.Field1), nameof(DataPoint.Field2) }, LabelColumnName = nameof(DataPoint.Label), LambdaLatent = 0.01f, diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs index d22f238e5d..cdacd51b93 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/GamWithOptions.cs @@ -158,8 +158,8 @@ private static IEnumerable GenerateData(int numExamples = 25000, Features = new float[2] { centeredFloat(), centeredFloat() } }; // Compute the label from the shape functions and add noise. - data.Label = Sigmoid(Parabola(data.Features[0]) - + SimplePiecewise(data.Features[1]) + centeredFloat()) > 0.5; + data.Label = Sigmoid(Parabola(data.Features[0]) + + SimplePiecewise(data.Features[1]) + centeredFloat()) > 0.5; yield return data; } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude index 43358c3441..d6f7e53a24 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/BinaryClassification/MultipleFeatureColumnsBinaryClassification.ttinclude @@ -170,12 +170,12 @@ namespace Samples.Dynamic.Trainers.BinaryClassification Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}"); Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}"); Console.WriteLine($"F1 Score: {metrics.F1Score:F2}"); - Console.WriteLine($"Negative Precision: {metrics.NegativePrecision:F2}") - ; + Console.WriteLine($"Negative Precision: " + + $"{metrics.NegativePrecision:F2}"); Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}"); - Console.WriteLine($"Positive Precision: {metrics.PositivePrecision:F2}") - ; + Console.WriteLine($"Positive Precision: " + + $"{metrics.PositivePrecision:F2}"); Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}"); Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}");