Skip to content

Commit 2da72cb

Browse files
authored
Reformatted Regression samples to width 85 (dotnet#3948)
* Reformatted Regression samples * Untabified comments in tt files. * Removed extra lines * Removed extra lines and added necessary indents
1 parent ce9b38b commit 2da72cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+960
-552
lines changed

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/FastForest.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,46 @@ namespace Samples.Dynamic.Trainers.Regression
88
{
99
public static class FastForestRegression
1010
{
11-
// This example requires installation of additional NuGet package
12-
// <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>.
11+
// This example requires installation of additional NuGet
12+
// package for Microsoft.ML.FastTree found at
13+
// https://www.nuget.org/packages/Microsoft.ML.FastTree/
1314
public static void Example()
1415
{
15-
// Create a new context for ML.NET operations. It can be used for exception tracking and logging,
16-
// as a catalog of available operations and as the source of randomness.
17-
// Setting the seed to a fixed number in this example to make outputs deterministic.
16+
// Create a new context for ML.NET operations. It can be used for
17+
// exception tracking and logging, as a catalog of available operations
18+
// and as the source of randomness. Setting the seed to a fixed number
19+
// in this example to make outputs deterministic.
1820
var mlContext = new MLContext(seed: 0);
1921

2022
// Create a list of training data points.
2123
var dataPoints = GenerateRandomDataPoints(1000);
2224

23-
// Convert the list of data points to an IDataView object, which is consumable by ML.NET API.
25+
// Convert the list of data points to an IDataView object, which is
26+
// consumable by ML.NET API.
2427
var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints);
2528

2629
// Define the trainer.
27-
var pipeline = mlContext.Regression.Trainers.FastForest(labelColumnName: nameof(DataPoint.Label), featureColumnName: nameof(DataPoint.Features));
30+
var pipeline = mlContext.Regression.Trainers.FastForest(
31+
labelColumnName: nameof(DataPoint.Label),
32+
featureColumnName: nameof(DataPoint.Features));
2833

2934
// Train the model.
3035
var model = pipeline.Fit(trainingData);
3136

32-
// Create testing data. Use different random seed to make it different from training data.
33-
var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(5, seed: 123));
37+
// Create testing data. Use different random seed to make it different
38+
// from training data.
39+
var testData = mlContext.Data.LoadFromEnumerable(
40+
GenerateRandomDataPoints(5, seed: 123));
3441

3542
// Run the model on test data set.
3643
var transformedTestData = model.Transform(testData);
3744

3845
// Convert IDataView object to a list.
39-
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
46+
var predictions = mlContext.Data.CreateEnumerable<Prediction>(
47+
transformedTestData, reuseRowObject: false).ToList();
4048

41-
// Look at 5 predictions for the Label, side by side with the actual Label for comparison.
49+
// Look at 5 predictions for the Label, side by side with the actual
50+
// Label for comparison.
4251
foreach (var p in predictions)
4352
Console.WriteLine($"Label: {p.Label:F3}, Prediction: {p.Score:F3}");
4453

@@ -60,7 +69,8 @@ public static void Example()
6069
// RSquared: 0.96 (closer to 1 is better. The worest case is 0)
6170
}
6271

63-
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int seed=0)
72+
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
73+
int seed=0)
6474
{
6575
var random = new Random(seed);
6676
for (int i = 0; i < count; i++)
@@ -70,12 +80,14 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int se
7080
{
7181
Label = label,
7282
// Create random features that are correlated with the label.
73-
Features = Enumerable.Repeat(label, 50).Select(x => x + (float)random.NextDouble()).ToArray()
83+
Features = Enumerable.Repeat(label, 50).Select(
84+
x => x + (float)random.NextDouble()).ToArray()
7485
};
7586
}
7687
}
7788

78-
// Example with label and 50 feature values. A data set is a collection of such examples.
89+
// Example with label and 50 feature values. A data set is a collection of
90+
// such examples.
7991
private class DataPoint
8092
{
8193
public float Label { get; set; }
@@ -95,10 +107,12 @@ private class Prediction
95107
// Print some evaluation metrics to regression problems.
96108
private static void PrintMetrics(RegressionMetrics metrics)
97109
{
98-
Console.WriteLine($"Mean Absolute Error: {metrics.MeanAbsoluteError:F2}");
99-
Console.WriteLine($"Mean Squared Error: {metrics.MeanSquaredError:F2}");
100-
Console.WriteLine($"Root Mean Squared Error: {metrics.RootMeanSquaredError:F2}");
101-
Console.WriteLine($"RSquared: {metrics.RSquared:F2}");
110+
Console.WriteLine("Mean Absolute Error: " + metrics.MeanAbsoluteError);
111+
Console.WriteLine("Mean Squared Error: " + metrics.MeanSquaredError);
112+
Console.WriteLine(
113+
"Root Mean Squared Error: " + metrics.RootMeanSquaredError);
114+
115+
Console.WriteLine("RSquared: " + metrics.RSquared);
102116
}
103117
}
104118
}

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/FastForest.tt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<#@ include file="RegressionSamplesTemplate.ttinclude"#>
22

33
<#+
4-
string ClassHeader = @"// This example requires installation of additional NuGet package
5-
// <a href=""https://www.nuget.org/packages/Microsoft.ML.FastTree/"">Microsoft.ML.FastTree</a>. ";
4+
string ClassHeader = @"// This example requires installation of additional NuGet
5+
// package for Microsoft.ML.FastTree found at
6+
// https://www.nuget.org/packages/Microsoft.ML.FastTree/";
67

78
string ClassName="FastForestRegression";
89
string ExtraUsing = null;
9-
string Trainer = @"FastForest(labelColumnName: nameof(DataPoint.Label), featureColumnName: nameof(DataPoint.Features))";
10+
string Trainer = @"FastForest(
11+
labelColumnName: nameof(DataPoint.Label),
12+
featureColumnName: nameof(DataPoint.Features))";
13+
1014
string TrainerOptions = null;
1115

1216
string ExpectedOutputPerInstance= @"// Expected output:

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/FastForestWithOptions.cs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ namespace Samples.Dynamic.Trainers.Regression
99
{
1010
public static class FastForestWithOptionsRegression
1111
{
12-
// This example requires installation of additional NuGet package
13-
// <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>.
12+
// This example requires installation of additional NuGet
13+
// package for Microsoft.ML.FastTree found at
14+
// https://www.nuget.org/packages/Microsoft.ML.FastTree/
1415
public static void Example()
1516
{
16-
// Create a new context for ML.NET operations. It can be used for exception tracking and logging,
17-
// as a catalog of available operations and as the source of randomness.
18-
// Setting the seed to a fixed number in this example to make outputs deterministic.
17+
// Create a new context for ML.NET operations. It can be used for
18+
// exception tracking and logging, as a catalog of available operations
19+
// and as the source of randomness. Setting the seed to a fixed number
20+
// in this example to make outputs deterministic.
1921
var mlContext = new MLContext(seed: 0);
2022

2123
// Create a list of training data points.
2224
var dataPoints = GenerateRandomDataPoints(1000);
2325

24-
// Convert the list of data points to an IDataView object, which is consumable by ML.NET API.
26+
// Convert the list of data points to an IDataView object, which is
27+
// consumable by ML.NET API.
2528
var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints);
2629

2730
// Define trainer options.
@@ -38,21 +41,26 @@ public static void Example()
3841
};
3942

4043
// Define the trainer.
41-
var pipeline = mlContext.Regression.Trainers.FastForest(options);
44+
var pipeline =
45+
mlContext.Regression.Trainers.FastForest(options);
4246

4347
// Train the model.
4448
var model = pipeline.Fit(trainingData);
4549

46-
// Create testing data. Use different random seed to make it different from training data.
47-
var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(5, seed: 123));
50+
// Create testing data. Use different random seed to make it different
51+
// from training data.
52+
var testData = mlContext.Data.LoadFromEnumerable(
53+
GenerateRandomDataPoints(5, seed: 123));
4854

4955
// Run the model on test data set.
5056
var transformedTestData = model.Transform(testData);
5157

5258
// Convert IDataView object to a list.
53-
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
59+
var predictions = mlContext.Data.CreateEnumerable<Prediction>(
60+
transformedTestData, reuseRowObject: false).ToList();
5461

55-
// Look at 5 predictions for the Label, side by side with the actual Label for comparison.
62+
// Look at 5 predictions for the Label, side by side with the actual
63+
// Label for comparison.
5664
foreach (var p in predictions)
5765
Console.WriteLine($"Label: {p.Label:F3}, Prediction: {p.Score:F3}");
5866

@@ -74,7 +82,8 @@ public static void Example()
7482
// RSquared: 0.95 (closer to 1 is better. The worest case is 0)
7583
}
7684

77-
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int seed=0)
85+
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
86+
int seed=0)
7887
{
7988
var random = new Random(seed);
8089
for (int i = 0; i < count; i++)
@@ -84,12 +93,14 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int se
8493
{
8594
Label = label,
8695
// Create random features that are correlated with the label.
87-
Features = Enumerable.Repeat(label, 50).Select(x => x + (float)random.NextDouble()).ToArray()
96+
Features = Enumerable.Repeat(label, 50).Select(
97+
x => x + (float)random.NextDouble()).ToArray()
8898
};
8999
}
90100
}
91101

92-
// Example with label and 50 feature values. A data set is a collection of such examples.
102+
// Example with label and 50 feature values. A data set is a collection of
103+
// such examples.
93104
private class DataPoint
94105
{
95106
public float Label { get; set; }
@@ -109,10 +120,12 @@ private class Prediction
109120
// Print some evaluation metrics to regression problems.
110121
private static void PrintMetrics(RegressionMetrics metrics)
111122
{
112-
Console.WriteLine($"Mean Absolute Error: {metrics.MeanAbsoluteError:F2}");
113-
Console.WriteLine($"Mean Squared Error: {metrics.MeanSquaredError:F2}");
114-
Console.WriteLine($"Root Mean Squared Error: {metrics.RootMeanSquaredError:F2}");
115-
Console.WriteLine($"RSquared: {metrics.RSquared:F2}");
123+
Console.WriteLine("Mean Absolute Error: " + metrics.MeanAbsoluteError);
124+
Console.WriteLine("Mean Squared Error: " + metrics.MeanSquaredError);
125+
Console.WriteLine(
126+
"Root Mean Squared Error: " + metrics.RootMeanSquaredError);
127+
128+
Console.WriteLine("RSquared: " + metrics.RSquared);
116129
}
117130
}
118131
}

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/FastForestWithOptions.tt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<#@ include file="RegressionSamplesTemplate.ttinclude"#>
22

33
<#+
4-
string ClassHeader = @"// This example requires installation of additional NuGet package
5-
// <a href=""https://www.nuget.org/packages/Microsoft.ML.FastTree/"">Microsoft.ML.FastTree</a>. ";
4+
string ClassHeader = @"// This example requires installation of additional NuGet
5+
// package for Microsoft.ML.FastTree found at
6+
// https://www.nuget.org/packages/Microsoft.ML.FastTree/";
67

78
string ClassName="FastForestWithOptionsRegression";
89
string ExtraUsing = "using Microsoft.ML.Trainers.FastTree;";

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/FastTree.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,46 @@ namespace Samples.Dynamic.Trainers.Regression
88
{
99
public static class FastTreeRegression
1010
{
11-
// This example requires installation of additional NuGet package
12-
// <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>.
11+
// This example requires installation of additional NuGet
12+
// package for Microsoft.ML.FastTree found at
13+
// https://www.nuget.org/packages/Microsoft.ML.FastTree/
1314
public static void Example()
1415
{
15-
// Create a new context for ML.NET operations. It can be used for exception tracking and logging,
16-
// as a catalog of available operations and as the source of randomness.
17-
// Setting the seed to a fixed number in this example to make outputs deterministic.
16+
// Create a new context for ML.NET operations. It can be used for
17+
// exception tracking and logging, as a catalog of available operations
18+
// and as the source of randomness. Setting the seed to a fixed number
19+
// in this example to make outputs deterministic.
1820
var mlContext = new MLContext(seed: 0);
1921

2022
// Create a list of training data points.
2123
var dataPoints = GenerateRandomDataPoints(1000);
2224

23-
// Convert the list of data points to an IDataView object, which is consumable by ML.NET API.
25+
// Convert the list of data points to an IDataView object, which is
26+
// consumable by ML.NET API.
2427
var trainingData = mlContext.Data.LoadFromEnumerable(dataPoints);
2528

2629
// Define the trainer.
27-
var pipeline = mlContext.Regression.Trainers.FastTree(labelColumnName: nameof(DataPoint.Label), featureColumnName: nameof(DataPoint.Features));
30+
var pipeline = mlContext.Regression.Trainers.FastForest(
31+
labelColumnName: nameof(DataPoint.Label),
32+
featureColumnName: nameof(DataPoint.Features));
2833

2934
// Train the model.
3035
var model = pipeline.Fit(trainingData);
3136

32-
// Create testing data. Use different random seed to make it different from training data.
33-
var testData = mlContext.Data.LoadFromEnumerable(GenerateRandomDataPoints(5, seed: 123));
37+
// Create testing data. Use different random seed to make it different
38+
// from training data.
39+
var testData = mlContext.Data.LoadFromEnumerable(
40+
GenerateRandomDataPoints(5, seed: 123));
3441

3542
// Run the model on test data set.
3643
var transformedTestData = model.Transform(testData);
3744

3845
// Convert IDataView object to a list.
39-
var predictions = mlContext.Data.CreateEnumerable<Prediction>(transformedTestData, reuseRowObject: false).ToList();
46+
var predictions = mlContext.Data.CreateEnumerable<Prediction>(
47+
transformedTestData, reuseRowObject: false).ToList();
4048

41-
// Look at 5 predictions for the Label, side by side with the actual Label for comparison.
49+
// Look at 5 predictions for the Label, side by side with the actual
50+
// Label for comparison.
4251
foreach (var p in predictions)
4352
Console.WriteLine($"Label: {p.Label:F3}, Prediction: {p.Score:F3}");
4453

@@ -60,7 +69,8 @@ public static void Example()
6069
// RSquared: 0.99 (closer to 1 is better. The worest case is 0)
6170
}
6271

63-
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int seed=0)
72+
private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count,
73+
int seed=0)
6474
{
6575
var random = new Random(seed);
6676
for (int i = 0; i < count; i++)
@@ -70,12 +80,14 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int se
7080
{
7181
Label = label,
7282
// Create random features that are correlated with the label.
73-
Features = Enumerable.Repeat(label, 50).Select(x => x + (float)random.NextDouble()).ToArray()
83+
Features = Enumerable.Repeat(label, 50).Select(
84+
x => x + (float)random.NextDouble()).ToArray()
7485
};
7586
}
7687
}
7788

78-
// Example with label and 50 feature values. A data set is a collection of such examples.
89+
// Example with label and 50 feature values. A data set is a collection of
90+
// such examples.
7991
private class DataPoint
8092
{
8193
public float Label { get; set; }
@@ -95,10 +107,12 @@ private class Prediction
95107
// Print some evaluation metrics to regression problems.
96108
private static void PrintMetrics(RegressionMetrics metrics)
97109
{
98-
Console.WriteLine($"Mean Absolute Error: {metrics.MeanAbsoluteError:F2}");
99-
Console.WriteLine($"Mean Squared Error: {metrics.MeanSquaredError:F2}");
100-
Console.WriteLine($"Root Mean Squared Error: {metrics.RootMeanSquaredError:F2}");
101-
Console.WriteLine($"RSquared: {metrics.RSquared:F2}");
110+
Console.WriteLine("Mean Absolute Error: " + metrics.MeanAbsoluteError);
111+
Console.WriteLine("Mean Squared Error: " + metrics.MeanSquaredError);
112+
Console.WriteLine(
113+
"Root Mean Squared Error: " + metrics.RootMeanSquaredError);
114+
115+
Console.WriteLine("RSquared: " + metrics.RSquared);
102116
}
103117
}
104118
}

docs/samples/Microsoft.ML.Samples/Dynamic/Trainers/Regression/FastTree.tt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<#@ include file="RegressionSamplesTemplate.ttinclude"#>
22

33
<#+
4-
string ClassHeader = @"// This example requires installation of additional NuGet package
5-
// <a href=""https://www.nuget.org/packages/Microsoft.ML.FastTree/"">Microsoft.ML.FastTree</a>. ";
4+
string ClassHeader = @"// This example requires installation of additional NuGet
5+
// package for Microsoft.ML.FastTree found at
6+
// https://www.nuget.org/packages/Microsoft.ML.FastTree/";
67

78
string ClassName="FastTreeRegression";
89
string ExtraUsing = null;
9-
string Trainer = @"FastTree(labelColumnName: nameof(DataPoint.Label), featureColumnName: nameof(DataPoint.Features))";
10+
string Trainer = @"FastForest(
11+
labelColumnName: nameof(DataPoint.Label),
12+
featureColumnName: nameof(DataPoint.Features))";
1013
string TrainerOptions = null;
1114

1215
string ExpectedOutputPerInstance= @"// Expected output:

0 commit comments

Comments
 (0)