-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Reformatting BinaryClassification samples to width 85 #3946
Merged
Merged
Changes from 59 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
cdf6b36
reformatted BinaryClassification samples
sierralee51 7abb9d1
Update AveragedPerceptron.cs
sierralee51 5c3214b
Update AveragedPerceptronWithOptions.cs
sierralee51 74935ee
Update AveragedPerceptron.cs
sierralee51 e9891f9
Update AveragedPerceptron.cs
sierralee51 c9dcd03
Update BinaryClassification.ttinclude
sierralee51 384f983
Update FactorizationMachine.cs
sierralee51 885f820
Update FastForest.cs
sierralee51 1d1679b
Update FastForestWithOptions.cs
sierralee51 f3ec594
Update FastTree.cs
sierralee51 fb62ed5
Update FastTreeWithOptions.cs
sierralee51 c243e2e
Update FieldAwareFactorizationMachine.cs
sierralee51 5458e79
Update FieldAwareFactorizationMachine.cs
sierralee51 60130f3
Update FieldAwareFactorizationMachine.tt
sierralee51 edcb4f5
Update FieldAwareFactorizationMachineWithOptions.cs
sierralee51 3d8613e
Update FieldAwareFactorizationMachine.cs
sierralee51 5aabe0e
Update FieldAwareFactorizationMachineWithOptions.tt
sierralee51 85036e2
Update LbfgsLogisticRegression.cs
sierralee51 92c6c19
Update LbfgsLogisticRegressionWithOptions.cs
sierralee51 f0990a1
Update LightGbm.cs
sierralee51 672b785
Update LightGbmWithOptions.cs
sierralee51 c41905d
Update LinearSvm.cs
sierralee51 e93c699
Update LinearSvmWithOptions.cs
sierralee51 cbbee59
Update MultipleFeatureColumnsBinaryClassification.ttinclude
sierralee51 2fc5e20
Update PriorTrainer.cs
sierralee51 a43123c
Update AveragedPerceptron.cs
sierralee51 58484e2
Update AveragedPerceptronWithOptions.cs
sierralee51 a42c2e8
Update BinaryClassification.ttinclude
sierralee51 a9afb72
Update FactorizationMachine.cs
sierralee51 e780b0d
Update FastForestWithOptions.cs
sierralee51 617a5c5
Update FastTree.cs
sierralee51 f95144b
Update FastTreeWithOptions.cs
sierralee51 ff86eca
Update LbfgsLogisticRegression.cs
sierralee51 5b7734e
Update LbfgsLogisticRegressionWithOptions.cs
sierralee51 b0c0813
Update LightGbm.cs
sierralee51 92d564d
Update LightGbmWithOptions.cs
sierralee51 061a83a
Update LinearSvm.cs
sierralee51 0402c90
Update LinearSvmWithOptions.cs
sierralee51 5c28cf6
Update SdcaLogisticRegression.cs
sierralee51 d39a4a2
Update SdcaLogisticRegressionWithOptions.cs
sierralee51 fef50fe
Update SdcaNonCalibrated.cs
sierralee51 deac2b1
Update SdcaNonCalibratedWithOptions.cs
sierralee51 a808724
Update SdcaNonCalibrated.cs
sierralee51 31f95e3
Update SdcaLogisticRegressionWithOptions.cs
sierralee51 1b05112
Update SdcaLogisticRegression.cs
sierralee51 47481ed
Update SgdCalibrated.cs
sierralee51 371e043
Update SgdCalibratedWithOptions.cs
sierralee51 254fdef
Update SgdNonCalibrated.cs
sierralee51 b860f30
Update SgdNonCalibratedWithOptions.cs
sierralee51 664aa71
Update SymbolicSgdLogisticRegression.cs
sierralee51 f6871c8
Update SymbolicSgdLogisticRegressionWithOptions.cs
sierralee51 539fe74
Update Program.cs
sierralee51 ed51348
Update Program.cs
sierralee51 d112945
Update Program.cs
sierralee51 3af17a8
Update Program.cs
sierralee51 93a98fe
Update Program.cs
sierralee51 652f39e
Update Program.cs
sierralee51 0857a13
fixed tab issues
sierralee51 6eac51a
fixed indentations
sierralee51 109a4cd
fixed commented-on parts
sierralee51 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,29 @@ public static void Example() | |
}; | ||
|
||
// Define the trainer. | ||
var pipeline = mlContext.BinaryClassification.Trainers.AveragedPerceptron(options); | ||
var pipeline = mlContext.BinaryClassification.Trainers | ||
.AveragedPerceptron(options); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah noticed that a couple minutes ago...looking for the tt/ttinclude file that is probably causing it |
||
// 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<Prediction>(transformedTestData, reuseRowObject: false).ToList(); | ||
var predictions = mlContext.Data | ||
.CreateEnumerable<Prediction>(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 +67,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 +92,9 @@ public static void Example() | |
// Precision || 0.7402 | 0.7061 | | ||
} | ||
|
||
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int seed=0) | ||
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, | ||
int seed=0) | ||
|
||
{ | ||
var random = new Random(seed); | ||
float randomFloat() => (float)random.NextDouble(); | ||
|
@@ -93,13 +105,18 @@ private static IEnumerable<DataPoint> 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,11 +139,16 @@ 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()); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line