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 75b25dcb86..1da43a7790 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 @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Microsoft.ML; @@ -27,9 +28,8 @@ public static void Example() // 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 scoredDataPreview = scoredData.Preview(); - - PrintRowViewValues(scoredDataPreview); + var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); + PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView // Score 4.18144 // Score -14.10248 @@ -45,8 +45,9 @@ public static void Example() // 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).Preview(); - PrintRowViewValues(finalData); + var finalData = calibratorTransformer.Transform(scoredData); + var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); // Score 4.18144 Probability 0.9856767 // Score -14.10248 Probability 7.890148E-07 // Score 2.731951 Probability 0.9416927 @@ -54,19 +55,27 @@ public static void Example() // Score 5.36571 Probability 0.9955735 } - private static void PrintRowViewValues(Microsoft.ML.Data.DataDebuggerPreview data) + private static void PrintScore(IEnumerable values, int numRows) { - var firstRows = data.RowView.Take(5); + foreach (var value in values.Take(numRows)) + Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); + } + + 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); + } - foreach (Microsoft.ML.Data.DataDebuggerPreview.RowInfo row in firstRows) - { - foreach (var kvPair in row.Values) - { - if (kvPair.Key.Equals("Score") || kvPair.Key.Equals("Probability")) - Console.Write($" {kvPair.Key} {kvPair.Value} "); - } - Console.WriteLine(); - } + private class ScoreValue + { + public float Score { get; set; } + } + + private class ScoreAndProbabilityValue + { + public float Score { get; set; } + public float Probability { get; set; } } } } 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 1bddd25d94..15a3162d4e 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 @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Microsoft.ML; @@ -27,9 +28,9 @@ public static void Example() // 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 scoredDataPreview = scoredData.Preview(); + var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); - PrintRowViewValues(scoredDataPreview); + PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView // Score 4.18144 // Score -14.10248 @@ -45,8 +46,9 @@ public static void Example() // 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).Preview(); - PrintRowViewValues(finalData); + var finalData = calibratorTransformer.Transform(scoredData); + var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); // Score 4.18144 Probability 0.8 // Score -14.10248 Probability 1E-15 // Score 2.731951 Probability 0.7370371 @@ -54,19 +56,27 @@ public static void Example() // Score 5.36571 Probability 0.8958333 } - private static void PrintRowViewValues(Microsoft.ML.Data.DataDebuggerPreview data) + private static void PrintScore(IEnumerable values, int numRows) { - var firstRows = data.RowView.Take(5); + foreach (var value in values.Take(numRows)) + Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); + } + + 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); + } - foreach (Microsoft.ML.Data.DataDebuggerPreview.RowInfo row in firstRows) - { - foreach (var kvPair in row.Values) - { - if (kvPair.Key.Equals("Score") || kvPair.Key.Equals("Probability")) - Console.Write($" {kvPair.Key} {kvPair.Value} "); - } - Console.WriteLine(); - } + private class ScoreValue + { + public float Score { get; set; } + } + + private class ScoreAndProbabilityValue + { + public float Score { get; set; } + public float Probability { get; set; } } } } 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 81f23a0974..84a004b1c5 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 @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Microsoft.ML; @@ -27,9 +28,8 @@ public static void Example() // 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 scoredDataPreview = scoredData.Preview(); - - PrintRowViewValues(scoredDataPreview); + var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); + PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView // Score 4.18144 // Score -14.10248 @@ -45,28 +45,37 @@ public static void Example() // 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).Preview(); - PrintRowViewValues(finalData); - // Score 4.18144 Probability 0.775 - // Score -14.10248 Probability 0.01923077 - // Score 2.731951 Probability 0.7738096 - // Score -2.554229 Probability 0.2011494 - // Score 5.36571 Probability 0.9117647 + var finalData = calibratorTransformer.Transform(scoredData); + var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); + // Score 4.18144 Probability 0.775 + // Score -14.10248 Probability 0.01923077 + // Score 2.731951 Probability 0.7738096 + // Score -2.554229 Probability 0.2011494 + // Score 5.36571 Probability 0.9117647 } - private static void PrintRowViewValues(Microsoft.ML.Data.DataDebuggerPreview data) + private static void PrintScore(IEnumerable values, int numRows) { - var firstRows = data.RowView.Take(5); + foreach (var value in values.Take(numRows)) + Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); + } + + 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); + } - foreach (Microsoft.ML.Data.DataDebuggerPreview.RowInfo row in firstRows) - { - foreach (var kvPair in row.Values) - { - if (kvPair.Key.Equals("Score") || kvPair.Key.Equals("Probability")) - Console.Write($" {kvPair.Key} {kvPair.Value} "); - } - Console.WriteLine(); - } + private class ScoreValue + { + public float Score { get; set; } + } + + private class ScoreAndProbabilityValue + { + public float Score { get; set; } + public float Probability { get; set; } } } } 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 f78f61de22..aa0d7d0798 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 @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Microsoft.ML; @@ -27,9 +28,8 @@ public static void Example() // 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 scoredDataPreview = scoredData.Preview(); - - PrintRowViewValues(scoredDataPreview); + var outScores = mlContext.Data.CreateEnumerable(scoredData, reuseRowObject: false); + PrintScore(outScores, 5); // Preview of scoredDataPreview.RowView // Score 4.18144 // Score -14.10248 @@ -45,8 +45,9 @@ public static void Example() // 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).Preview(); - PrintRowViewValues(finalData); + var finalData = calibratorTransformer.Transform(scoredData); + var outScoresAndProbabilities = mlContext.Data.CreateEnumerable(finalData, reuseRowObject: false); + PrintScoreAndProbability(outScoresAndProbabilities, 5); // Score 4.18144 Probability 0.8511352 // Score -14.10248 Probability 0.001633563 // Score 2.731951 Probability 0.7496456 @@ -54,19 +55,27 @@ public static void Example() // Score 5.36571 Probability 0.9065308 } - private static void PrintRowViewValues(Microsoft.ML.Data.DataDebuggerPreview data) + private static void PrintScore(IEnumerable values, int numRows) { - var firstRows = data.RowView.Take(5); + foreach (var value in values.Take(numRows)) + Console.WriteLine("{0, -10} {1, -10}", "Score", value.Score); + } + + 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); + } - foreach (Microsoft.ML.Data.DataDebuggerPreview.RowInfo row in firstRows) - { - foreach (var kvPair in row.Values) - { - if (kvPair.Key.Equals("Score") || kvPair.Key.Equals("Probability")) - Console.Write($" {kvPair.Key} {kvPair.Value} "); - } - Console.WriteLine(); - } + private class ScoreValue + { + public float Score { get; set; } + } + + private class ScoreAndProbabilityValue + { + public float Score { get; set; } + public float Probability { get; set; } } } }