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

Conversation

sierralee51
Copy link
Contributor

Guidelines followed:
-85 characters per line
-Use 4 spaces for indentation
-Dot and open parentheses stay on same line as function
-If not a preexisting line under line that we break, add an extra line after it
-Don't indent comments
-Don't break a comment if it represents output
-Don't break links
-If applicable, break right before $
-Keep math op together

Fix for issue #3478
*There are a couple exceptions to the 85 char. limit that have been approved by Natalie

@sierralee51
Copy link
Contributor Author

Just noticed that, like last time, there are some extra spaces before comments that don't show up on VisualStudio. Fixing them through GitHub right now.

@sierralee51
Copy link
Contributor Author

Just noticed that, like last time, there are some extra spaces before comments that don't show up on VisualStudio. Fixing them through GitHub right now.

In fixing these extra spaces before comments, I also realized that all my indentations were messed up. The extra spaces in my PR should be fixed, and I am now investigating the issue of extra whitespace in GitHub, as I know that Sayan and I both encountered this despite using spaces rather than tabs. A quick search has shown that this is a relatively common isssue, so I'll be looking into ways to prevent this in the future.

// 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
Copy link
Member

Choose a reason for hiding this comment

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

[](start = 0, length = 2)

why do you have these tabs?

var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data
.CreateEnumerable<Prediction>(transformedTestData,
reuseRowObject: false).ToList();
Copy link
Member

Choose a reason for hiding this comment

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

   [](start = 0, length = 2)

tabs. please convert tabs to spaces.
https://blogs.msdn.microsoft.com/zainnab/2010/03/14/how-to-convert-tabs-to-spaces-and-vice-versa/

};
}
}

// Example with label and 20 feature values. A data set is a collection of such examples.
// Example with label and 20 feature values. A data set is a collection of
// such examples.
Copy link
Member

Choose a reason for hiding this comment

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

Align the //

var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data
.CreateEnumerable<Prediction>(transformedTestData,
reuseRowObject: false).ToList();
Copy link
Member

Choose a reason for hiding this comment

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

reuseRowObject: false).ToList(); [](start = 2, length = 32)

this needs to be indented after .CreateEnumerable with 4 splaces.


// Look at 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}");
Copy link
Member

Choose a reason for hiding this comment

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

$"Prediction: {p.PredictedLabel}"); [](start = 6, length = 35)

same here but after Console.

@@ -56,7 +69,9 @@ public static void Example()
// Label: 3, Prediction: 3

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

Choose a reason for hiding this comment

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

.Evaluate(transformedTestData); [](start = 9, length = 31)

indent

// 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.";
Copy link
Member

Choose a reason for hiding this comment

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

Alight all //

// Apply PairwiseCoupling multiclass meta trainer on top of
// binary trainer.
.Append(mlContext.MulticlassClassification.Trainers
.PairwiseCoupling(
Copy link
Member

Choose a reason for hiding this comment

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

.PairwiseCoupling( [](start = 10, length = 18)

indent after .Append with 4 spaces

// binary trainer.
.Append(mlContext.MulticlassClassification.Trainers
.PairwiseCoupling(
mlContext.BinaryClassification.Trainers.SdcaLogisticRegression()));
Copy link
Member

Choose a reason for hiding this comment

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

mlContext.BinaryClassification.Trainers.SdcaLogisticRegression())); [](start = 3, length = 67)

indent after .PairwiseCoupling with 4 spaces.

// Create testing data. Use different random seed to make it different
// from training data.
var testData = mlContext.Data
.LoadFromEnumerable(GenerateRandomDataPoints(500, seed: 123));
Copy link
Member

Choose a reason for hiding this comment

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

.LoadFromEnumerable(GenerateRandomDataPoints(500, seed: 123)); [](start = 9, length = 62)

indent after var with 4 spaces.

@codemzs
Copy link
Member

codemzs commented Jul 2, 2019

It seems the indentation needs to be fixed. My comments apply at many places where I have not commented.

mlContext.Transforms.Conversion.MapValueToKey(nameof(DataPoint.Label))
// Apply LbfgsMaximumEntropy multiclass trainer.
.Append(mlContext.MulticlassClassification.Trainers.LbfgsMaximumEntropy());
// Convert the string labels into key types.
Copy link
Member

Choose a reason for hiding this comment

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

📝 Line should be indented by 4 more spaces

.Append(mlContext.MulticlassClassification.Trainers.LbfgsMaximumEntropy());
// Convert the string labels into key types.
mlContext.Transforms.Conversion
.MapValueToKey(nameof(DataPoint.Label))
Copy link
Member

Choose a reason for hiding this comment

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

📝 Line should be indented by 4 more spaces

.MapValueToKey(nameof(DataPoint.Label))
// Apply LbfgsMaximumEntropy multiclass trainer.
.Append(mlContext.MulticlassClassification.Trainers
.LbfgsMaximumEntropy());
Copy link
Member

Choose a reason for hiding this comment

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

  1. Wrap the entire argument if possible (before mlContext)
  2. Indent this line an additional 4 spaces (8 total from current location)

var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
var predictions = mlContext.Data
.CreateEnumerable<Prediction>(transformedTestData,
reuseRowObject: false).ToList();
Copy link
Member

Choose a reason for hiding this comment

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

📝 This is difficult to read. See preferred form in #3941 (comment)


// Look at 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}");
Copy link
Member

Choose a reason for hiding this comment

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

📝 Multi-line body of foreach needs braces

// Generates random uniform doubles in [-0.5, 0.5)
// range with labels 1, 2 or 3.
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
int seed=0)
Copy link
Member

Choose a reason for hiding this comment

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

📝 Wrap no arguments, or wrap all arguments with one argument per line

@@ -8,7 +8,8 @@ string TrainerOptions = null;
string OptionsInclude = "";
string Comments = "";
bool CacheData = false;
string DataGenerationComments= "// Generates random uniform doubles in [-0.5, 0.5) range with labels 1, 2 or 3.";
string DataGenerationComments= "// Generates random uniform doubles in [-0.5, 0.5)"
+ "\n // range with labels 1, 2 or 3.";
Copy link
Member

Choose a reason for hiding this comment

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

📝 Place \n at the end of the preceding line

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

// Convert the string labels into key types.
Copy link
Member

Choose a reason for hiding this comment

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

📝 Needs 4 more spaces

mlContext.Transforms.Conversion.MapValueToKey("Label")
// Apply LbfgsMaximumEntropy multiclass trainer.
.Append(mlContext.MulticlassClassification.Trainers
.LbfgsMaximumEntropy(options));
Copy link
Member

Choose a reason for hiding this comment

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

📝 See earlier comment regarding this wrapping

.Append(mlContext.MulticlassClassification.Trainers
.OneVersusAll(
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

.Append(mlContext.MulticlassClassification.Trainers
.PairwiseCoupling(
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

Copy link
Contributor

@sayanshaw24 sayanshaw24 left a comment

Choose a reason for hiding this comment

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

Looks good to me. There are just a few indents you could add, and empty lines you could remove (@RadicalRayan noted most of them). Take a look at our comments and merge when the tests pass.

@@ -12,7 +12,9 @@ string TrainerOptions = @"LbfgsMaximumEntropyMulticlassTrainer.Options

string OptionsInclude = "using Microsoft.ML.Trainers;";
string Comments = "";
string DataGenerationComments= "// Generates random uniform doubles in [-0.5, 0.5) range with labels 1, 2 or 3.";
string DataGenerationComments= "// Generates random uniform doubles in [-0.5, 0.5)"
+ "\n // range with labels 1, 2 or 3.";
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe indent the comment "// range with labels . . ." with the same indent as the comment above it "Generates random . . . " ? There are more instances of this, so I guess there's a tt file you'd have to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That isn't a comment. It's part of the string

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Empty line

@sierralee51 sierralee51 merged commit 4fecfb2 into dotnet:master Jul 3, 2019
Dmitry-A pushed a commit to Dmitry-A/machinelearning that referenced this pull request Jul 24, 2019
* reformatted multiclassclassification samples

* fixing errors

* reformatted MulticlassClassification samples

* Update LbfgsMaximumEntropy.cs

getting rid of whitespace

* Update LbfgsMaximumEntropy.cs

* Update LbfgsMaximumEntropyWithOptions.cs

getting rid of whitespace

* Update LightGbmWithOptions.cs

fixing whitespace

* Update LbfgsMaximumEntropy.cs

* Update LightGbm.cs

fixing whitespace

* Update LightGbm.cs

fixing whitespace

* Update LightGbmWithOptions.cs

fixing whitespace

* Update MulticlassClassification.ttinclude

fixing whitespace

* Update MulticlassClassification.ttinclude

fixing whitespace

* Update NaiveBayes.cs

fixing whitespace

* Update NaiveBayes.tt

fixing whitespace

* Update NaiveBayes.tt

* Update OneVersusAll.cs

fixing whitespace

* Update PairwiseCoupling.cs

fixing whitespace

* Update SdcaMaximumEntropy.cs

fixing whitespace

* Update SdcaMaximumEntropyWithOptions.cs

fixing whitespace

* Update SdcaNonCalibrated.cs

fixing whitespace

* Update SdcaNonCalibratedWithOptions.cs

fixing whitespace

* Update SdcaNonCalibrated.cs

fixing whitespace

* Update SdcaNonCalibrated.cs

* Update LbfgsMaximumEntropy.cs

* Update LbfgsMaximumEntropy.cs

* Update LbfgsMaximumEntropyWithOptions.cs

* Update LightGbm.cs

* Update LightGbmWithOptions.cs

* Update MulticlassClassification.ttinclude

* Update NaiveBayes.cs

* Update OneVersusAll.cs

* Update PairwiseCoupling.cs

* Update SdcaMaximumEntropy.cs

* Update SdcaMaximumEntropy.cs

* Update SdcaMaximumEntropyWithOptions.cs

* Update SdcaNonCalibrated.cs

* Update SdcaNonCalibratedWithOptions.cs

* fixed tabbing issue

* fixed indentations

* aligned comments

* fixed some indentation and spacing issues

* fixed extra empty lines

* fixed some more indentation issue
@ghost ghost locked as resolved and limited conversation to collaborators Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants