Skip to content

BinaryClassification Calibrators: Replace Preview API with IDataView based getter API. #3353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;

Expand Down Expand Up @@ -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<ScoreValue>(scoredData, reuseRowObject: false);
PrintScore(outScores, 5);
// Preview of scoredDataPreview.RowView
// Score 4.18144
// Score -14.10248
Expand All @@ -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);
var finalData = calibratorTransformer.Transform(scoredData);
var outScoresAndProbabilities = mlContext.Data.CreateEnumerable<ScoreAndProbabilityValue>(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
// Score -2.554229 Probability 0.07556222
// Score 5.36571 Probability 0.9955735
}

private static void PrintRowViewValues(Microsoft.ML.Data.DataDebuggerPreview data)
private static void PrintScore(IEnumerable<ScoreValue> 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<ScoreAndProbabilityValue> 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; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;

Expand Down Expand Up @@ -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<ScoreValue>(scoredData, reuseRowObject: false);

PrintRowViewValues(scoredDataPreview);
PrintScore(outScores, 5);
// Preview of scoredDataPreview.RowView
// Score 4.18144
// Score -14.10248
Expand All @@ -45,28 +46,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);
var finalData = calibratorTransformer.Transform(scoredData);
var outScoresAndProbabilities = mlContext.Data.CreateEnumerable<ScoreAndProbabilityValue>(finalData, reuseRowObject: false);
PrintScoreAndProbability(outScoresAndProbabilities, 5);
// Score 4.18144 Probability 0.8
// Score -14.10248 Probability 1E-15
// Score 2.731951 Probability 0.7370371
// Score -2.554229 Probability 0.2063954
// Score 5.36571 Probability 0.8958333
}

private static void PrintRowViewValues(Microsoft.ML.Data.DataDebuggerPreview data)
private static void PrintScore(IEnumerable<ScoreValue> 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<ScoreAndProbabilityValue> 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; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;

Expand Down Expand Up @@ -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<ScoreValue>(scoredData, reuseRowObject: false);
PrintScore(outScores, 5);
// Preview of scoredDataPreview.RowView
// Score 4.18144
// Score -14.10248
Expand All @@ -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<ScoreAndProbabilityValue>(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<ScoreValue> 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<ScoreAndProbabilityValue> 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; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;

Expand Down Expand Up @@ -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<ScoreValue>(scoredData, reuseRowObject: false);
PrintScore(outScores, 5);
// Preview of scoredDataPreview.RowView
// Score 4.18144
// Score -14.10248
Expand All @@ -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);
var finalData = calibratorTransformer.Transform(scoredData);
var outScoresAndProbabilities = mlContext.Data.CreateEnumerable<ScoreAndProbabilityValue>(finalData, reuseRowObject: false);
PrintScoreAndProbability(outScoresAndProbabilities, 5);
// Score 4.18144 Probability 0.8511352
// Score -14.10248 Probability 0.001633563
// Score 2.731951 Probability 0.7496456
// Score -2.554229 Probability 0.2206048
// Score 5.36571 Probability 0.9065308
}

private static void PrintRowViewValues(Microsoft.ML.Data.DataDebuggerPreview data)
private static void PrintScore(IEnumerable<ScoreValue> 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<ScoreAndProbabilityValue> 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; }
}
}
}