Skip to content

Reformatting MulticlassClassification samples to width 85 #3942

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 45 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
539a0f7
reformatted multiclassclassification samples
sierralee51 Jul 1, 2019
d18c419
fixing errors
sierralee51 Jul 1, 2019
0b4aff6
reformatted MulticlassClassification samples
sierralee51 Jul 1, 2019
f84939f
Update LbfgsMaximumEntropy.cs
sierralee51 Jul 1, 2019
130c6da
Update LbfgsMaximumEntropy.cs
sierralee51 Jul 1, 2019
71e4c19
Update LbfgsMaximumEntropyWithOptions.cs
sierralee51 Jul 1, 2019
8166627
Update LightGbmWithOptions.cs
sierralee51 Jul 1, 2019
5ea92f3
Update LbfgsMaximumEntropy.cs
sierralee51 Jul 1, 2019
b63c891
Update LightGbm.cs
sierralee51 Jul 1, 2019
4d37328
Update LightGbm.cs
sierralee51 Jul 1, 2019
6421a8b
Update LightGbmWithOptions.cs
sierralee51 Jul 1, 2019
79093c8
Update MulticlassClassification.ttinclude
sierralee51 Jul 1, 2019
4c2f723
Update MulticlassClassification.ttinclude
sierralee51 Jul 1, 2019
4a48dc5
Update NaiveBayes.cs
sierralee51 Jul 1, 2019
cc1b3f8
Update NaiveBayes.tt
sierralee51 Jul 1, 2019
c6d4cfd
Update NaiveBayes.tt
sierralee51 Jul 1, 2019
97b3c99
Update OneVersusAll.cs
sierralee51 Jul 1, 2019
6be7d8a
Update PairwiseCoupling.cs
sierralee51 Jul 1, 2019
3f74187
Update SdcaMaximumEntropy.cs
sierralee51 Jul 1, 2019
0d23ad8
Update SdcaMaximumEntropyWithOptions.cs
sierralee51 Jul 1, 2019
c728577
Update SdcaNonCalibrated.cs
sierralee51 Jul 1, 2019
6e82a10
Update SdcaNonCalibratedWithOptions.cs
sierralee51 Jul 1, 2019
1f1ff3b
Update SdcaNonCalibrated.cs
sierralee51 Jul 1, 2019
239e26a
Update SdcaNonCalibrated.cs
sierralee51 Jul 1, 2019
32db971
Update LbfgsMaximumEntropy.cs
sierralee51 Jul 1, 2019
e3e595b
Update LbfgsMaximumEntropy.cs
sierralee51 Jul 1, 2019
969af4d
Update LbfgsMaximumEntropyWithOptions.cs
sierralee51 Jul 1, 2019
b18c508
Update LightGbm.cs
sierralee51 Jul 1, 2019
1af1554
Update LightGbmWithOptions.cs
sierralee51 Jul 1, 2019
d0e1a01
Update MulticlassClassification.ttinclude
sierralee51 Jul 1, 2019
092808d
Update NaiveBayes.cs
sierralee51 Jul 1, 2019
e943230
Update OneVersusAll.cs
sierralee51 Jul 1, 2019
9d014e3
Update PairwiseCoupling.cs
sierralee51 Jul 1, 2019
407c4d8
Update SdcaMaximumEntropy.cs
sierralee51 Jul 1, 2019
b4c9575
Update SdcaMaximumEntropy.cs
sierralee51 Jul 1, 2019
053c85b
Update SdcaMaximumEntropyWithOptions.cs
sierralee51 Jul 1, 2019
0d2baa6
Update SdcaNonCalibrated.cs
sierralee51 Jul 1, 2019
6e410cc
Update SdcaNonCalibratedWithOptions.cs
sierralee51 Jul 1, 2019
278b743
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
sierralee51 Jul 1, 2019
85ed0e6
fixed tabbing issue
sierralee51 Jul 2, 2019
f51c147
fixed indentations
sierralee51 Jul 2, 2019
1e9a3d8
aligned comments
sierralee51 Jul 2, 2019
c3d3499
fixed some indentation and spacing issues
sierralee51 Jul 2, 2019
e497794
fixed extra empty lines
sierralee51 Jul 2, 2019
6224ed5
fixed some more indentation issue
sierralee51 Jul 2, 2019
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
Prev Previous commit
Next Next commit
aligned comments
  • Loading branch information
sierralee51 committed Jul 2, 2019
commit 1e9a3d881bd1a7ee7c303cb56aa77c1cd6399b0e
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public static void Example()
.MapValueToKey(nameof(DataPoint.Label))

// Apply a multiclass trainer.
.Append(mlContext.MulticlassClassification.Trainers.LightGbm());
.Append(mlContext.MulticlassClassification.Trainers
.LightGbm());

// Train the model.
var model = pipeline.Fit(trainingData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,54 @@ public static class NaiveBayes
// Naive Bayes classifier is based on Bayes' theorem.
// It assumes independence among the presence of features in a class even
// though they may be dependent on each other. It is a multi-class trainer
// that accepts binary feature values of type float, i.e., feature values
// are either true or false. Specifically a feature value greater than zero
// is treated as true, zero or less is treated as false.
// that accepts binary feature values of type float, i.e., feature values
// are either true or false. Specifically a feature value greater than zero
// is treated as true, zero or less is treated as false.
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 =
// Convert the string labels into key types.
mlContext.Transforms.Conversion
// Convert the string labels into key types.
mlContext.Transforms.Conversion
.MapValueToKey(nameof(DataPoint.Label))

// Apply NaiveBayes multiclass trainer.
.Append(mlContext.MulticlassClassification.Trainers
// Apply NaiveBayes multiclass trainer.
.Append(mlContext.MulticlassClassification.Trainers
.NaiveBayes());


// 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<Prediction>(transformedTestData,
reuseRowObject: false).ToList();
.CreateEnumerable<Prediction>(transformedTestData,
reuseRowObject: false).ToList();

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

// Expected output:
// Label: 1, Prediction: 1
Expand All @@ -70,7 +69,7 @@ public static void Example()

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

PrintMetrics(metrics);

Expand All @@ -93,8 +92,8 @@ public static void Example()


// Generates random uniform doubles in [-0.5, 0.5) range with labels
// 1, 2 or 3. For NaiveBayes values greater than zero are treated as true,
// zero or less are treated as false.
// 1, 2 or 3. For NaiveBayes values greater than zero are treated as true,
// zero or less are treated as false.
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
int seed=0)

Expand All @@ -110,7 +109,7 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
Label = (uint)label,
// Create random features that are correlated with the label.
// The feature values are slightly increased by adding a
// constant multiple of label.
// constant multiple of label.
Features = Enumerable.Repeat(label, 20)
.Select(x => randomFloat() + label * 0.2f).ToArray()

Expand All @@ -119,7 +118,7 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
}

// Example with label and 20 feature values. A data set is a collection of
// such examples.
// such examples.
private class DataPoint
{
public uint Label { get; set; }
Expand All @@ -143,7 +142,7 @@ public static void PrintMetrics(MulticlassClassificationMetrics metrics)
Console.WriteLine($"Macro Accuracy: {metrics.MacroAccuracy:F2}");
Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}");
Console.WriteLine(
$"Log Loss Reduction: {metrics.LogLossReduction:F2}\n");
$"Log Loss Reduction: {metrics.LogLossReduction:F2}\n");

Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ string Comments= @"
// Naive Bayes classifier is based on Bayes' theorem.
// It assumes independence among the presence of features in a class even
// though they may be dependent on each other. It is a multi-class trainer
// that accepts binary feature values of type float, i.e., feature values
// are either true or false. Specifically a feature value greater than zero
// is treated as true, zero or less is treated as false.";
// that accepts binary feature values of type float, i.e., feature values
// are either true or false. Specifically a feature value greater than zero
// is treated as true, zero or less is treated as false.";

string DataGenerationComments= @"
// Generates random uniform doubles in [-0.5, 0.5) range with labels
// 1, 2 or 3. For NaiveBayes values greater than zero are treated as true,
// zero or less are treated as false.";
// 1, 2 or 3. For NaiveBayes values greater than zero are treated as true,
// zero or less are treated as false.";

string ExpectedOutputPerInstance= @"// Expected output:
// Label: 1, Prediction: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,49 @@ public static class OneVersusAll
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 =
// Convert the string labels into key types.
mlContext.Transforms.Conversion.MapValueToKey("Label")
// Apply OneVersusAll multiclass meta trainer on top of
// Convert the string labels into key types.
mlContext.Transforms.Conversion.MapValueToKey("Label")
// Apply OneVersusAll multiclass meta trainer on top of
// binary trainer.
.Append(mlContext.MulticlassClassification.Trainers
.Append(mlContext.MulticlassClassification.Trainers
.OneVersusAll(
mlContext.BinaryClassification.Trainers.SdcaLogisticRegression()));
mlContext.BinaryClassification.Trainers.SdcaLogisticRegression()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line


// 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<Prediction>(transformedTestData,
reuseRowObject: false).ToList();
.CreateEnumerable<Prediction>(transformedTestData,
reuseRowObject: false).ToList();

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

// Expected output:
// Label: 1, Prediction: 1
Expand All @@ -64,7 +64,7 @@ public static void Example()

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

PrintMetrics(metrics);

Expand Down Expand Up @@ -102,7 +102,7 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
Label = (uint)label,
// Create random features that are correlated with the label.
// The feature values are slightly increased by adding a
// constant multiple of label.
// constant multiple of label.
Features = Enumerable.Repeat(label, 20)
.Select(x => randomFloat() + label * 0.2f).ToArray()

Expand All @@ -111,7 +111,7 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
}

// Example with label and 20 feature values. A data set is a collection of
// such examples.
// such examples.
private class DataPoint
{
public uint Label { get; set; }
Expand All @@ -135,7 +135,7 @@ public static void PrintMetrics(MulticlassClassificationMetrics metrics)
Console.WriteLine($"Macro Accuracy: {metrics.MacroAccuracy:F2}");
Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}");
Console.WriteLine(
$"Log Loss Reduction: {metrics.LogLossReduction:F2}\n");
$"Log Loss Reduction: {metrics.LogLossReduction:F2}\n");

Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,49 @@ public static class PairwiseCoupling
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 =
// Convert the string labels into key types.
mlContext.Transforms.Conversion.MapValueToKey("Label")
// Apply PairwiseCoupling multiclass meta trainer on top of
// Convert the string labels into key types.
mlContext.Transforms.Conversion.MapValueToKey("Label")
// Apply PairwiseCoupling multiclass meta trainer on top of
// binary trainer.
.Append(mlContext.MulticlassClassification.Trainers
.Append(mlContext.MulticlassClassification.Trainers
.PairwiseCoupling(
mlContext.BinaryClassification.Trainers.SdcaLogisticRegression()));
mlContext.BinaryClassification.Trainers.SdcaLogisticRegression()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line


// 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<Prediction>(transformedTestData,
reuseRowObject: false).ToList();
.CreateEnumerable<Prediction>(transformedTestData,
reuseRowObject: false).ToList();

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

// Expected output:
// Label: 1, Prediction: 1
Expand All @@ -64,7 +64,7 @@ public static void Example()

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

PrintMetrics(metrics);

Expand Down Expand Up @@ -102,9 +102,9 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
Label = (uint)label,
// Create random features that are correlated with the label.
// The feature values are slightly increased by adding a
// constant multiple of label.
// constant multiple of label.
Features = Enumerable.Repeat(label, 20)
.Select(x => randomFloat() + label * 0.2f).ToArray()
.Select(x => randomFloat() + label * 0.2f).ToArray()

};
}
Expand Down Expand Up @@ -135,9 +135,10 @@ public static void PrintMetrics(MulticlassClassificationMetrics metrics)
Console.WriteLine($"Macro Accuracy: {metrics.MacroAccuracy:F2}");
Console.WriteLine($"Log Loss: {metrics.LogLoss:F2}");
Console.WriteLine(
$"Log Loss Reduction: {metrics.LogLossReduction:F2}\n");
$"Log Loss Reduction: {metrics.LogLossReduction:F2}\n");

Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable());
}
}
}

Loading