From f880b7b62dcf3c18a4a2797ecfaadfc0ce2c6471 Mon Sep 17 00:00:00 2001 From: sierralee51 <36902786+sierralee51@users.noreply.github.com> Date: Wed, 26 Jun 2019 15:20:07 -0700 Subject: [PATCH 01/27] Added a comment. --- docs/samples/Microsoft.ML.Samples/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index eb49938927..333a331286 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -9,6 +9,7 @@ public static class Program internal static void RunAll() { + // Samples counter. int samples = 0; foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { From 4f06b84b47252809e0f51beb0bb5f00cbb3903b0 Mon Sep 17 00:00:00 2001 From: sierralee51 <36902786+sierralee51@users.noreply.github.com> Date: Wed, 26 Jun 2019 17:23:42 -0700 Subject: [PATCH 02/27] reformatted ModelOperations samples to width 85 --- .../Dynamic/ModelOperations/SaveLoadModel.cs | 15 ++++++++++----- .../Dynamic/ModelOperations/SaveLoadModelFile.cs | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs index a5f70802bb..6137194558 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs @@ -9,8 +9,8 @@ public class SaveLoadModel { public static void Example() { - // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, - // as well as the source of randomness. + // Create a new ML context, for ML.NET operations. It can be used for + // exception tracking and logging, as well as the source of randomness. var mlContext = new MLContext(); // Generate sample data. @@ -25,7 +25,8 @@ public static void Example() var outputColumnName = nameof(Transformation.Key); // Transform. - ITransformer model = mlContext.Transforms.Conversion.MapValueToKey(outputColumnName, inputColumnName).Fit(dataView); + ITransformer model = mlContext.Transforms.Conversion.MapValueToKey( + outputColumnName, inputColumnName).Fit(dataView); // Save model. mlContext.Model.Save(model, dataView.Schema, "model.zip"); @@ -35,11 +36,15 @@ public static void Example() model = mlContext.Model.Load(file, out DataViewSchema schema); // Create a prediction engine from the model for feeding new data. - var engine = mlContext.Model.CreatePredictionEngine(model); + var engine = mlContext.Model.CreatePredictionEngine(model); + var transformation = engine.Predict(new Data() { Value = "abc" }); // Print transformation to console. - Console.WriteLine("Value: {0}\t Key:{1}", transformation.Value, transformation.Key); + Console.WriteLine("Value: {0}\t Key:{1}", transformation.Value, + transformation.Key); + // Value: abc Key:1 } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs index 9884f8c8e9..60bb4a4a9f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs @@ -9,8 +9,8 @@ public class SaveLoadModelFile { public static void Example() { - // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, - // as well as the source of randomness. + // Create a new ML context, for ML.NET operations. It can be used for + // exception tracking and logging, as well as the source of randomness. var mlContext = new MLContext(); // Generate sample data. @@ -25,7 +25,8 @@ public static void Example() var outputColumnName = nameof(Transformation.Key); // Transform. - ITransformer model = mlContext.Transforms.Conversion.MapValueToKey(outputColumnName, inputColumnName).Fit(dataView); + ITransformer model = mlContext.Transforms.Conversion.MapValueToKey( + outputColumnName, inputColumnName).Fit(dataView); // Save model. mlContext.Model.Save(model, dataView.Schema, "model.zip"); @@ -34,11 +35,15 @@ public static void Example() model = mlContext.Model.Load("model.zip", out DataViewSchema schema); // Create a prediction engine from the model for feeding new data. - var engine = mlContext.Model.CreatePredictionEngine(model); + var engine = mlContext.Model.CreatePredictionEngine(model); + var transformation = engine.Predict(new Data() { Value = "abc" }); // Print transformation to console. - Console.WriteLine("Value: {0}\t Key:{1}", transformation.Value, transformation.Key); + Console.WriteLine("Value: {0}\t Key:{1}", transformation.Value, + transformation.Key); + // Value: abc Key:1 } From 3ce38a3bd52921c97de3b84b91f1faedba1924bc Mon Sep 17 00:00:00 2001 From: sierralee51 <36902786+sierralee51@users.noreply.github.com> Date: Thu, 27 Jun 2019 16:40:41 -0700 Subject: [PATCH 03/27] Fixed commented-on parts of MachineOperations & reformatted DataOperations --- .../Dynamic/DataOperations/BootstrapSample.cs | 32 ++++--- .../Dynamic/DataOperations/Cache.cs | 62 ++++++++----- .../DataOperations/CrossValidationSplit.cs | 88 ++++++++++++++----- .../DataOperations/DataViewEnumerable.cs | 43 ++++++--- .../DataOperations/DataViewEnumerable.tt | 39 +++++--- .../DataOperations/FilterRowsByColumn.cs | 39 +++++--- .../DataOperations/FilterRowsByColumn.tt | 31 +++++-- .../FilterRowsByKeyColumnFraction.cs | 44 +++++++--- .../FilterRowsByMissingValues.cs | 26 ++++-- .../DataOperations/LoadFromEnumerable.cs | 58 +++++++----- .../DataOperations/SaveAndLoadFromBinary.cs | 22 +++-- .../DataOperations/SaveAndLoadFromText.cs | 20 +++-- .../Dynamic/DataOperations/ShuffleRows.cs | 30 +++++-- .../Dynamic/DataOperations/ShuffleRows.tt | 22 +++-- .../Dynamic/DataOperations/SkipRows.cs | 27 ++++-- .../Dynamic/DataOperations/SkipRows.tt | 19 ++-- .../Dynamic/DataOperations/TakeRows.cs | 28 ++++-- .../Dynamic/DataOperations/TakeRows.tt | 22 +++-- .../TemperatureAndLatitude.ttinclude | 8 +- .../Dynamic/DataOperations/TrainTestSplit.cs | 45 +++++++--- .../Dynamic/ModelOperations/SaveLoadModel.cs | 8 +- .../ModelOperations/SaveLoadModelFile.cs | 8 +- 22 files changed, 496 insertions(+), 225 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/BootstrapSample.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/BootstrapSample.cs index 33413352de..be93d56fae 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/BootstrapSample.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/BootstrapSample.cs @@ -7,8 +7,9 @@ public static class BootstrapSample { 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. + // 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -23,20 +24,27 @@ public static void Example() var data = mlContext.Data.LoadFromEnumerable(rawData); - // Now take a bootstrap sample of this dataset to create a new dataset. The bootstrap is a resampling technique that - // creates a training set of the same size by picking with replacement from the original dataset. With the bootstrap, - // we expect that the resampled dataset will have about 63% of the rows of the original dataset (i.e. 1-e^-1), with some - // rows represented more than once. - // BootstrapSample is a streaming implementation of the boostrap that enables sampling from a dataset too large to hold in memory. - // To enable streaming, BootstrapSample approximates the bootstrap by sampling each row according to a Poisson(1) distribution. - // Note that this streaming approximation treats each row independently, thus the resampled dataset is not guaranteed to be the - // same length as the input dataset. - // Let's take a look at the behavior of the BootstrapSample by examining a few draws: + // Now take a bootstrap sample of this dataset to create a new dataset. + // The bootstrap is a resampling technique that creates a training set + // of the same size by picking with replacement from the original + // dataset. With the bootstrap, we expect that the resampled dataset + // will have about 63% of the rows of the original dataset + // (i.e. 1-e^-1), with some rows represented more than once. + // BootstrapSample is a streaming implementation of the boostrap that + // enables sampling from a dataset too large to hold in memory. To + // enable streaming, BootstrapSample approximates the bootstrap by + // sampling each row according to a Poisson(1) distribution. Note that + // this streaming approximation treats each row independently, thus the + // resampled dataset is not guaranteed to be the same length as the + // input dataset. Let's take a look at the behavior of the + // BootstrapSample by examining a few draws: for (int i = 0; i < 3; i++) { var resample = mlContext.Data.BootstrapSample(data, seed: i); - var enumerable = mlContext.Data.CreateEnumerable(resample, reuseRowObject: false); + var enumerable = mlContext.Data + .CreateEnumerable(resample, reuseRowObject: false); + Console.WriteLine($"Label\tFeature"); foreach (var row in enumerable) { diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs index 4ea7c33723..b1e73977bb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs @@ -8,56 +8,78 @@ public static class Cache { 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. + // Create a new context for ML.NET operations. It can be used for except + // ion tracking and logging, as a catalog of available operations and as + // the source of randomness. var mlContext = new MLContext(); var data = DatasetUtils.LoadHousingRegressionDataset(mlContext); // Time how long it takes to page through the records if we don't cache. - (int lines, double columnAverage, double elapsedSeconds) = TimeToScanIDataView(mlContext, data); - Console.WriteLine($"Lines={lines}, averageOfColumn0={columnAverage:0.00} and took {elapsedSeconds} seconds."); + (int lines, double columnAverage, double elapsedSeconds) = + TimeToScanIDataView(mlContext, data); + + Console.WriteLine($"Lines={lines}," + + $"averageOfColumn0={columnAverage:0.00}and took {elapsedSeconds}" + + $"seconds."); // Expected output (time is approximate): // Lines=506, averageOfColumn0=564.17 and took 0.314 seconds. // Now create a cached view of the data. var cachedData = mlContext.Data.Cache(data); - // Time how long it takes to page through the records the first time they're accessed after a cache is applied. - // This iteration will be longer than subsequent calls, as the dataset is being accessed and stored for later. - // Note that this operation may be relatively quick, as the system may have cached the file. - (lines, columnAverage, elapsedSeconds) = TimeToScanIDataView(mlContext, cachedData); - Console.WriteLine($"Lines={lines}, averageOfColumn0={columnAverage:0.00} and took {elapsedSeconds} seconds."); + // Time how long it takes to page through the records the first time + // they're accessed after a cache is applied. This iteration will be + // longer than subsequent calls, as the dataset is being accessed and + // stored for later. Note that this operation may be relatively quick, + // as the system may have cached the file. + (lines, columnAverage, elapsedSeconds) = TimeToScanIDataView(mlContext, + cachedData); + + Console.WriteLine($"Lines={lines}," + + $"averageOfColumn0={columnAverage:0.00} and took {elapsedSeconds}" + + $"seconds."); // Expected output (time is approximate): // Lines=506, averageOfColumn0=564.17 and took 0.056 seconds. - // Time how long it takes to page through the records now that the data is cached. After the first iteration that caches the IDataView, - // future iterations, like this one, are faster because they are pulling from data cached in memory. - (lines, columnAverage, elapsedSeconds) = TimeToScanIDataView(mlContext, cachedData); - Console.WriteLine($"Lines={lines}, averageOfColumn0={columnAverage:0.00} and took {elapsedSeconds} seconds."); + // Time how long it takes to page through the records now that the data + // is cached. After the first iteration that caches the IDataView, + // future iterations, like this one, are faster because they are pulling + // from data cached in memory. + (lines, columnAverage, elapsedSeconds) = TimeToScanIDataView(mlContext, + cachedData); + + Console.WriteLine( + $"Lines={lines}, averageOfColumn0={columnAverage:0.00} and took " + + $"{elapsedSeconds} seconds."); // Expected output (time is approximate): // Lines=506, averageOfColumn0=564.17 and took 0.006 seconds. } - private static (int lines, double columnAverage, double elapsedSeconds) TimeToScanIDataView(MLContext mlContext, IDataView data) + private static (int lines, double columnAverage, double elapsedSeconds) + TimeToScanIDataView(MLContext mlContext, IDataView data) { int lines = 0; double columnAverage = 0.0; - var enumerable = mlContext.Data.CreateEnumerable(data, reuseRowObject: true); + var enumerable = mlContext.Data + .CreateEnumerable(data, reuseRowObject: true); + var watch = System.Diagnostics.Stopwatch.StartNew(); foreach (var row in enumerable) { lines++; - columnAverage += row.MedianHomeValue + row.CrimesPerCapita + row.PercentResidental + row.PercentNonRetail + row.CharlesRiver - + row.NitricOxides + row.RoomsPerDwelling + row.PercentPre40s + row.EmploymentDistance - + row.HighwayDistance + row.TaxRate + row.TeacherRatio; + columnAverage += row.MedianHomeValue + row.CrimesPerCapita + + row.PercentResidental + row.PercentNonRetail + row.CharlesRiver + + row.NitricOxides + row.RoomsPerDwelling + row.PercentPre40s + + row.EmploymentDistance + row.HighwayDistance + row.TaxRate + + row.TeacherRatio; } watch.Stop(); columnAverage /= lines; var elapsed = watch.Elapsed; return (lines, columnAverage, elapsed.Seconds); - } + } /// /// A class to hold the raw housing regression rows. @@ -79,4 +101,4 @@ public sealed class HousingRegression } } -} +} \ No newline at end of file diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/CrossValidationSplit.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/CrossValidationSplit.cs index d7f3faad94..cbe68ba117 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/CrossValidationSplit.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/CrossValidationSplit.cs @@ -17,16 +17,28 @@ public static void Example() // Generate some data points. var examples = GenerateRandomDataPoints(10); - // Convert the examples list to an IDataView object, which is consumable by ML.NET API. + // Convert the examples list to an IDataView object, which is consumable + // by ML.NET API. var dataview = mlContext.Data.LoadFromEnumerable(examples); - // Cross validation splits your data randomly into set of "folds", and creates groups of Train and Test sets, - // where for each group, one fold is the Test and the rest of the folds the Train. - // So below, we specify Group column as the column containing the sampling keys. - // If we pass that column to cross validation it would be used to break data into certain chunks. - var folds = mlContext.Data.CrossValidationSplit(dataview, numberOfFolds: 3, samplingKeyColumnName: "Group"); - var trainSet = mlContext.Data.CreateEnumerable(folds[0].TrainSet, reuseRowObject: false); - var testSet = mlContext.Data.CreateEnumerable(folds[0].TestSet, reuseRowObject: false); + // Cross validation splits your data randomly into set of "folds", and + // creates groups of Train and Test sets, where for each group, one fold + // is the Test and the rest of the folds the Train. So below, we specify + // Group column as the column containing the sampling keys. If we pass + // that column to cross validation it would be used to break data into + // certain chunks. + var folds = mlContext.Data + .CrossValidationSplit(dataview, numberOfFolds:3, + samplingKeyColumnName: "Group"); + + var trainSet = mlContext.Data + .CreateEnumerable(folds[0].TrainSet, + reuseRowObject: false); + + var testSet = mlContext.Data + .CreateEnumerable(folds[0].TestSet, + reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. @@ -43,8 +55,14 @@ public static void Example() // [Group, 0], [Features, 0.9060271] // [Group, 0], [Features, 0.2737045] - trainSet = mlContext.Data.CreateEnumerable(folds[1].TrainSet, reuseRowObject: false); - testSet = mlContext.Data.CreateEnumerable(folds[1].TestSet, reuseRowObject: false); + trainSet = mlContext.Data + .CreateEnumerable(folds[1].TrainSet, + reuseRowObject: false); + + testSet = mlContext.Data + .CreateEnumerable(folds[1].TestSet, + reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. // [Group, 0], [Features, 0.7262433] @@ -60,8 +78,14 @@ public static void Example() // [Group, 1], [Features, 0.2060332] // [Group, 1], [Features, 0.4421779] - trainSet = mlContext.Data.CreateEnumerable(folds[2].TrainSet, reuseRowObject: false); - testSet = mlContext.Data.CreateEnumerable(folds[2].TestSet, reuseRowObject: false); + trainSet = mlContext.Data + .CreateEnumerable(folds[2].TrainSet, + reuseRowObject: false); + + testSet = mlContext.Data + .CreateEnumerable(folds[2].TestSet, + reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. // [Group, 0], [Features, 0.7262433] @@ -79,8 +103,14 @@ public static void Example() // Example of a split without specifying a sampling key column. folds = mlContext.Data.CrossValidationSplit(dataview, numberOfFolds: 3); - trainSet = mlContext.Data.CreateEnumerable(folds[0].TrainSet, reuseRowObject: false); - testSet = mlContext.Data.CreateEnumerable(folds[0].TestSet, reuseRowObject: false); + trainSet = mlContext.Data + .CreateEnumerable(folds[0].TrainSet, + reuseRowObject: false); + + testSet = mlContext.Data + .CreateEnumerable(folds[0].TestSet, + reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. // [Group, 0], [Features, 0.7262433] @@ -96,8 +126,14 @@ public static void Example() // [Group, 2], [Features, 0.5588848] // [Group, 0], [Features, 0.9060271] - trainSet = mlContext.Data.CreateEnumerable(folds[1].TrainSet, reuseRowObject: false); - testSet = mlContext.Data.CreateEnumerable(folds[1].TestSet, reuseRowObject: false); + trainSet = mlContext.Data + .CreateEnumerable(folds[1].TrainSet, + reuseRowObject: false); + + testSet = mlContext.Data + .CreateEnumerable(folds[1].TestSet, + reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. // [Group, 2], [Features, 0.7680227] @@ -113,8 +149,13 @@ public static void Example() // [Group, 2], [Features, 0.9775497] // [Group, 0], [Features, 0.2737045] - trainSet = mlContext.Data.CreateEnumerable(folds[2].TrainSet, reuseRowObject: false); - testSet = mlContext.Data.CreateEnumerable(folds[2].TestSet, reuseRowObject: false); + trainSet = mlContext.Data + .CreateEnumerable(folds[2].TrainSet, + reuseRowObject: false); + + testSet = mlContext.Data.CreateEnumerable(folds[2].TestSet, + reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. // [Group, 0], [Features, 0.7262433] @@ -131,7 +172,9 @@ public static void Example() // [Group, 1], [Features, 0.4421779] } - private static IEnumerable GenerateRandomDataPoints(int count, int seed = 0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed = 0) + { var random = new Random(seed); for (int i = 0; i < count; i++) @@ -146,7 +189,8 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se } } - // Example with features and group column. A data set is a collection of such examples. + // Example with features and group column. A data set is a collection of + // such examples. private class DataPoint { public float Group { get; set; } @@ -155,7 +199,9 @@ private class DataPoint } // print helper - private static void PrintPreviewRows(IEnumerable trainSet, IEnumerable testSet) + private static void PrintPreviewRows(IEnumerable trainSet, + IEnumerable testSet) + { Console.WriteLine($"The data in the Train split."); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs index 667bd39758..239c998e4b 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs @@ -6,31 +6,41 @@ namespace Samples.Dynamic { public static class DataViewEnumerable { - // A simple case of creating IDataView from IEnumerable. + // A simple case of creating IDataView from + //IEnumerable. public static void Example() { - // Create a new context for ML.NET operations. It can be used for exception tracking and logging, + // 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. - IEnumerable enumerableOfData = GetSampleTemperatureData(5); + IEnumerable enumerableOfData = + GetSampleTemperatureData(5); // Load dataset into an IDataView. IDataView data = mlContext.Data.LoadFromEnumerable(enumerableOfData); - // We can now examine the records in the IDataView. We first create an enumerable of rows in the IDataView. - var rowEnumerable = mlContext.Data.CreateEnumerable(data, reuseRowObject: true); + // We can now examine the records in the IDataView. We first create an + // enumerable of rows in the IDataView. + var rowEnumerable = mlContext.Data + .CreateEnumerable(data, + reuseRowObject: true); - // SampleTemperatureDataWithLatitude has the definition of a Latitude column of type float. - // We can use the parameter ignoreMissingColumns to true to ignore any missing columns in the IDataView. - // The produced enumerable will have the Latitude field set to the default for the data type, in this case 0. - var rowEnumerableIgnoreMissing = mlContext.Data.CreateEnumerable(data, - reuseRowObject: true, ignoreMissingColumns: true); + // SampleTemperatureDataWithLatitude has the definition of a Latitude + // column of type float. We can use the parameter ignoreMissingColumns + // to true to ignore any missing columns in the IDataView. The produced + // enumerable will have the Latitude field set to the default for the + // data type, in this case 0. + var rowEnumerableIgnoreMissing = mlContext.Data + .CreateEnumerable(data, + reuseRowObject: true, ignoreMissingColumns: true); Console.WriteLine($"Date\tTemperature"); foreach (var row in rowEnumerable) - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine( + $"{row.Date.ToString("d")}\t{row.Temperature}"); // Expected output: // Date Temperature @@ -42,7 +52,8 @@ public static void Example() Console.WriteLine($"Date\tTemperature\tLatitude"); foreach (var row in rowEnumerableIgnoreMissing) - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}\t{row.Latitude}"); + Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}" + + $"\t{row.Latitude}"); // Expected output: // Date Temperature Latitude @@ -71,7 +82,9 @@ private class SampleTemperatureDataWithLatitude /// /// The number of examples to return. /// An enumerable of . - private static IEnumerable GetSampleTemperatureData(int exampleCount) + private static IEnumerable GetSampleTemperatureData( + int exampleCount) + { var rng = new Random(1234321); var date = new DateTime(2012, 1, 1); @@ -81,7 +94,9 @@ private static IEnumerable GetSampleTemperatureData(int e { date = date.AddDays(1); temperature += rng.Next(-5, 5); - yield return new SampleTemperatureData { Date = date, Temperature = temperature }; + yield return new SampleTemperatureData { Date = date, Temperature = + temperature }; + } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt index 680ef76b66..6618e2b9cc 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt @@ -3,29 +3,39 @@ string NameSpace = "Samples.Dynamic"; string ClassName="DataViewEnumerable"; string AddExtraClass = "true"; -string ExampleShortDoc = @"// A simple case of creating IDataView from IEnumerable."; -string Example = @"// Create a new context for ML.NET operations. It can be used for exception tracking and logging, +string ExampleShortDoc = @"// A simple case of creating IDataView from + //IEnumerable."; +string 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. - IEnumerable enumerableOfData = GetSampleTemperatureData(5); + IEnumerable enumerableOfData = + GetSampleTemperatureData(5); // Load dataset into an IDataView. IDataView data = mlContext.Data.LoadFromEnumerable(enumerableOfData); - // We can now examine the records in the IDataView. We first create an enumerable of rows in the IDataView. - var rowEnumerable = mlContext.Data.CreateEnumerable(data, reuseRowObject: true); - - // SampleTemperatureDataWithLatitude has the definition of a Latitude column of type float. - // We can use the parameter ignoreMissingColumns to true to ignore any missing columns in the IDataView. - // The produced enumerable will have the Latitude field set to the default for the data type, in this case 0. - var rowEnumerableIgnoreMissing = mlContext.Data.CreateEnumerable(data, - reuseRowObject: true, ignoreMissingColumns: true); + // We can now examine the records in the IDataView. We first create an + // enumerable of rows in the IDataView. + var rowEnumerable = mlContext.Data + .CreateEnumerable(data, + reuseRowObject: true); + + // SampleTemperatureDataWithLatitude has the definition of a Latitude + // column of type float. We can use the parameter ignoreMissingColumns + // to true to ignore any missing columns in the IDataView. The produced + // enumerable will have the Latitude field set to the default for the + // data type, in this case 0. + var rowEnumerableIgnoreMissing = mlContext.Data + .CreateEnumerable(data, + reuseRowObject: true, ignoreMissingColumns: true); Console.WriteLine($""Date\tTemperature""); foreach (var row in rowEnumerable) - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine( + $""{row.Date.ToString(""d"")}\t{row.Temperature}""); // Expected output: // Date Temperature @@ -37,7 +47,8 @@ string Example = @"// Create a new context for ML.NET operations. It can be used Console.WriteLine($""Date\tTemperature\tLatitude""); foreach (var row in rowEnumerableIgnoreMissing) - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}\t{row.Latitude}""); + Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}"" + + $""\t{row.Latitude}""); // Expected output: // Date Temperature Latitude @@ -46,4 +57,4 @@ string Example = @"// Create a new context for ML.NET operations. It can be used // 1/4/2012 34 0 // 1/5/2012 35 0 // 1/6/2012 35 0"; -#> +#> \ No newline at end of file diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs index bddc168e78..b6b1d9ead7 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs @@ -6,11 +6,13 @@ namespace Samples.Dynamic { public static class FilterRowsByColumn { - // // Sample class showing how to filter out some rows in IDataView. + // // Sample class showing how to filter out some rows in + // IDataView. 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. + // 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -21,7 +23,9 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerableOfData) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine( + $"{row.Date.ToString("d")}\t{row.Temperature}"); + } Console.WriteLine(); // Expected output: @@ -37,15 +41,24 @@ public static void Example() // 1/10/2012 30 // 1/11/2012 29 - // Filter the data by the values of the temperature. The lower bound is inclusive, the upper exclusive. - var filteredData = mlContext.Data.FilterRowsByColumn(data, columnName: "Temperature", lowerBound: 34, upperBound: 37); + // Filter the data by the values of the temperature. The lower bound is + // inclusive, the upper exclusive. + var filteredData = mlContext.Data + .FilterRowsByColumn(data, columnName: "Temperature", + lowerBound: 34, upperBound: 37); + + // Look at the filtered data and observe that values outside [34,37) + // have been dropped. + var enumerable = mlContext.Data + .CreateEnumerable(filteredData, + reuseRowObject: true); - // Look at the filtered data and observe that values outside [34,37) have been dropped. - var enumerable = mlContext.Data.CreateEnumerable(filteredData, reuseRowObject: true); Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerable) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine( + $"{row.Date.ToString("d")}\t{row.Temperature}"); + } // Expected output: @@ -69,7 +82,9 @@ private class SampleTemperatureData /// /// The number of examples to return. /// An enumerable of . - private static IEnumerable GetSampleTemperatureData(int exampleCount) + private static IEnumerable GetSampleTemperatureData( + int exampleCount) + { var rng = new Random(1234321); var date = new DateTime(2012, 1, 1); @@ -79,7 +94,9 @@ private static IEnumerable GetSampleTemperatureData(int e { date = date.AddDays(1); temperature += rng.Next(-5, 5); - yield return new SampleTemperatureData { Date = date, Temperature = temperature }; + yield return new SampleTemperatureData { Date = date, Temperature = + temperature }; + } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt index 4b8ed39faf..8e63e59679 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt @@ -3,9 +3,11 @@ string NameSpace = "Samples.Dynamic"; string ClassName="FilterRowsByColumn"; string AddExtraClass = null; -string ExampleShortDoc = @"// // Sample class showing how to filter out some rows in IDataView."; -string 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. +string ExampleShortDoc = @"// // Sample class showing how to filter out some rows in + // IDataView."; +string 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -16,7 +18,9 @@ string Example = @"// Create a new context for ML.NET operations. It can be used Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerableOfData) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine( + $""{row.Date.ToString(""d"")}\t{row.Temperature}""); + } Console.WriteLine(); // Expected output: @@ -32,15 +36,24 @@ string Example = @"// Create a new context for ML.NET operations. It can be used // 1/10/2012 30 // 1/11/2012 29 - // Filter the data by the values of the temperature. The lower bound is inclusive, the upper exclusive. - var filteredData = mlContext.Data.FilterRowsByColumn(data, columnName: ""Temperature"", lowerBound: 34, upperBound: 37); + // Filter the data by the values of the temperature. The lower bound is + // inclusive, the upper exclusive. + var filteredData = mlContext.Data + .FilterRowsByColumn(data, columnName: ""Temperature"", + lowerBound: 34, upperBound: 37); + + // Look at the filtered data and observe that values outside [34,37) + // have been dropped. + var enumerable = mlContext.Data + .CreateEnumerable(filteredData, + reuseRowObject: true); - // Look at the filtered data and observe that values outside [34,37) have been dropped. - var enumerable = mlContext.Data.CreateEnumerable(filteredData, reuseRowObject: true); Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerable) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine( + $""{row.Date.ToString(""d"")}\t{row.Temperature}""); + } // Expected output: diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByKeyColumnFraction.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByKeyColumnFraction.cs index 4074579614..6b95bdf05e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByKeyColumnFraction.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByKeyColumnFraction.cs @@ -11,7 +11,8 @@ public static class FilterRowsByKeyColumnFraction { public static void Example() { - // Create a new context for ML.NET operations. It can be used for exception tracking and logging, + // 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. var mlContext = new MLContext(); @@ -36,7 +37,9 @@ public static void Example() var transformedData = pipeline.Fit(data).Transform(data); // Before we apply a filter, examine all the records in the dataset. - var enumerable = mlContext.Data.CreateEnumerable(transformedData, reuseRowObject: true); + var enumerable = mlContext.Data + .CreateEnumerable(transformedData, reuseRowObject: true); + Console.WriteLine($"Age"); foreach (var row in enumerable) { @@ -56,12 +59,20 @@ public static void Example() // Now filter down to half the keys, choosing the lower half of values. // For the keys we have the sorted values: 1 1 2 2 2 3 4 4. - // Projected in the [0, 1[ interval as per: (key - 0.5)/(Count of Keys) the values of the keys for our data would be: + // Projected in the [0, 1[ interval as per: (key - 0.5)/(Count of Keys) + // the values of the keys for our data would be: // 0.125 0.125 0.375 0.375 0.375 0.625 0.875 0.875 - // so the keys resulting from filtering in the [0, 0.5 [ interval are the ones with normalized values 0.125 and 0.375, respectively keys + // so the keys resulting from filtering in the [0, 0.5 [ interval are + // the ones with normalized values 0.125 and 0.375, respectively keys // with values 1 and 2. - var filteredHalfData = mlContext.Data.FilterRowsByKeyColumnFraction(transformedData, columnName: "Age", lowerBound: 0, upperBound: 0.5); - var filteredHalfEnumerable = mlContext.Data.CreateEnumerable(filteredHalfData, reuseRowObject: true); + var filteredHalfData = mlContext.Data + .FilterRowsByKeyColumnFraction(transformedData, columnName: "Age", + lowerBound: 0, upperBound: 0.5); + + var filteredHalfEnumerable = mlContext.Data + .CreateEnumerable(filteredHalfData, + reuseRowObject: true); + Console.WriteLine($"Age"); foreach (var row in filteredHalfEnumerable) { @@ -76,12 +87,21 @@ public static void Example() // 2 // 1 - // As mentioned above, the normalized keys are: 0.125 0.125 0.375 0.375 0.375 0.625 0.875 0.875 - // so the keys resulting from filtering in the [0.3, 0.6 [ interval are the ones with normalized value 0.375, respectively key - // with value = 2. - var filteredMiddleData = mlContext.Data.FilterRowsByKeyColumnFraction(transformedData, columnName: "Age", lowerBound: 0.3, upperBound: 0.6); - // Look at the data and observe that values above 2 have been filtered out - var filteredMiddleEnumerable = mlContext.Data.CreateEnumerable(filteredMiddleData, reuseRowObject: true); + // As mentioned above, the normalized keys are: + // 0.125 0.125 0.375 0.375 0.375 0.625 0.875 0.875 + // so the keys resulting from filtering in the [0.3, 0.6 [ interval are + // the ones with normalized value 0.375, respectively key with + // value = 2. + var filteredMiddleData = mlContext.Data + .FilterRowsByKeyColumnFraction(transformedData, columnName: "Age", + lowerBound: 0.3, upperBound: 0.6); + + // Look at the data and observe that values above 2 have been filtered + // out + var filteredMiddleEnumerable = mlContext.Data + .CreateEnumerable(filteredMiddleData, + reuseRowObject: true); + Console.WriteLine($"Age"); foreach (var row in filteredMiddleEnumerable) { diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByMissingValues.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByMissingValues.cs index 306f4f5185..02f40a6d2c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByMissingValues.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByMissingValues.cs @@ -12,32 +12,40 @@ public class FilterRowsByMissingValues /// public static void Example() { - // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, - // as well as the source of randomness. + // Create a new ML context, for ML.NET operations. It can be used for + // exception tracking and logging, as well as the source of randomness. var mlContext = new MLContext(); // Create a small dataset as an IEnumerable. var samples = new List() { - new DataPoint(){ Feature1 = 21, Feature2 = new [] { 1, 2, float.NaN} }, + new DataPoint(){ Feature1 = 21, Feature2 = new [] { 1, 2, float.NaN} + }, + new DataPoint(){ Feature1 = 40, Feature2 = new [] { 1f, 2f, 3f} }, - new DataPoint(){ Feature1 = float.NaN, Feature2 = new [] { 1, 2, float.NaN} } + new DataPoint(){ Feature1 = float.NaN, Feature2 = new [] { 1, 2, + float.NaN} } + }; // Convert training data to IDataView. var data = mlContext.Data.LoadFromEnumerable(samples); // Filter out any row with an NaN values in either column - var filteredData = mlContext.Data.FilterRowsByMissingValues(data, new[] { "Feature1", "Feature2" }); + var filteredData = mlContext.Data + .FilterRowsByMissingValues(data, new[] { "Feature1", "Feature2" }); + + // Take a look at the resulting dataset and note that rows with NaNs are + // filtered out. Only the second data point is left + var enumerable = mlContext.Data + .CreateEnumerable(filteredData, reuseRowObject: true); - // Take a look at the resulting dataset and note that rows with NaNs are filtered out. - // Only the second data point is left - var enumerable = mlContext.Data.CreateEnumerable(filteredData, reuseRowObject: true); Console.WriteLine($"Feature1 Feature2"); foreach (var row in enumerable) { - Console.WriteLine($"{row.Feature1}\t({string.Join(", ", row.Feature2)})"); + Console.WriteLine($"{row.Feature1}" + + $"\t({string.Join(", ", row.Feature2)})"); } // Feature1 Feature2 diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/LoadFromEnumerable.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/LoadFromEnumerable.cs index 64bc929850..0bc83d8831 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/LoadFromEnumerable.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/LoadFromEnumerable.cs @@ -7,37 +7,48 @@ namespace Samples.Dynamic { public static class LoadFromEnumerable { - // Creating IDataView from IEnumerable, and setting the size of the vector at runtime. - // When the data model is defined through types, setting the size of the vector is done through the VectorType - // annotation. When the size of the data is not known at compile time, the Schema can be directly modified at runtime - // and the size of the vector set there. - // This is important, because most of the ML.NET trainers require the Features vector to be of known size. + // Creating IDataView from IEnumerable, and setting the size of the vector + // at runtime. When the data model is defined through types, setting the + // size of the vector is done through the VectorType annotation. When the + // size of the data is not known at compile time, the Schema can be directly + // modified at runtime and the size of the vector set there. This is + // important, because most of the ML.NET trainers require the Features + // vector to be of known size. 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. + // 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. IEnumerable enumerableKnownSize = new DataPointVector[] { - new DataPointVector{ Features = new float[]{ 1.2f, 3.4f, 4.5f, 3.2f, 7,5f } }, - new DataPointVector{ Features = new float[]{ 4.2f, 3.4f, 14.65f, 3.2f, 3,5f } }, - new DataPointVector{ Features = new float[]{ 1.6f, 3.5f, 4.5f, 6.2f, 3,5f } }, + new DataPointVector{ Features = new float[]{ 1.2f, 3.4f, 4.5f, 3.2f, + 7,5f } }, + + new DataPointVector{ Features = new float[]{ 4.2f, 3.4f, 14.65f, + 3.2f, 3,5f } }, + + new DataPointVector{ Features = new float[]{ 1.6f, 3.5f, 4.5f, 6.2f, + 3,5f } }, + }; // Load dataset into an IDataView. IDataView data = mlContext.Data.LoadFromEnumerable(enumerableKnownSize); var featureColumn = data.Schema["Features"].Type as VectorDataViewType; // Inspecting the schema - Console.WriteLine($"Is the size of the Features column known: {featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}"); + Console.WriteLine($"Is the size of the Features column known: " + + $"{featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}"); // Preview // // Is the size of the Features column known? True. // Size: 5. - // If the size of the vector is unknown at compile time, it can be set at runtime. + // If the size of the vector is unknown at compile time, it can be set + // at runtime. IEnumerable enumerableUnknownSize = new DataPoint[] { new DataPoint{ Features = new float[]{ 1.2f, 3.4f, 4.5f } }, @@ -45,12 +56,15 @@ public static void Example() new DataPoint{ Features = new float[]{ 1.6f, 3.5f, 4.5f } }, }; - // The feature dimension (typically this will be the Count of the array of the features vector - // known at runtime). + // The feature dimension (typically this will be the Count of the array + // of the features vector known at runtime). int featureDimension = 3; var definedSchema = SchemaDefinition.Create(typeof(DataPoint)); - featureColumn = definedSchema["Features"].ColumnType as VectorDataViewType; - Console.WriteLine($"Is the size of the Features column known: {featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}"); + featureColumn = definedSchema["Features"] + .ColumnType as VectorDataViewType; + + Console.WriteLine($"Is the size of the Features column known: " + + $"{featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}"); // Preview // @@ -58,15 +72,19 @@ public static void Example() // Size: 0. // Set the column type to be a known-size vector. - var vectorItemType = ((VectorDataViewType)definedSchema[0].ColumnType).ItemType; - definedSchema[0].ColumnType = new VectorDataViewType(vectorItemType, featureDimension); + var vectorItemType = ((VectorDataViewType)definedSchema[0].ColumnType) + .ItemType; + definedSchema[0].ColumnType = new VectorDataViewType(vectorItemType, + featureDimension); // Read the data into an IDataView with the modified schema supplied in - IDataView data2 = mlContext.Data.LoadFromEnumerable(enumerableUnknownSize, definedSchema); + IDataView data2 = mlContext.Data + .LoadFromEnumerable(enumerableUnknownSize, definedSchema); featureColumn = data2.Schema["Features"].Type as VectorDataViewType; // Inspecting the schema - Console.WriteLine($"Is the size of the Features column known: {featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}"); + Console.WriteLine($"Is the size of the Features column known: " + + $"{featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}"); // Preview // diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromBinary.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromBinary.cs index b6448ec857..9fa1253a62 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromBinary.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromBinary.cs @@ -9,9 +9,10 @@ public static class SaveAndLoadFromBinary { 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. @@ -24,18 +25,22 @@ public static void Example() new DataPoint(){ Label = 1, Features = 9}, }; - // 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. IDataView data = mlContext.Data.LoadFromEnumerable(dataPoints); - // Create a FileStream object and write the IDataView to it as a binary IDV file. + // Create a FileStream object and write the IDataView to it as a binary + // IDV file. using (FileStream stream = new FileStream("data.idv", FileMode.Create)) mlContext.Data.SaveAsBinary(data, stream); // Create an IDataView object by loading the binary IDV file. IDataView loadedData = mlContext.Data.LoadFromBinary("data.idv"); - // Inspect the data that is loaded from the previously saved binary file. - var loadedDataEnumerable = mlContext.Data.CreateEnumerable(loadedData, reuseRowObject: false); + // Inspect the data that is loaded from the previously saved binary file + var loadedDataEnumerable = mlContext.Data + .CreateEnumerable(loadedData, reuseRowObject: false); + foreach (DataPoint row in loadedDataEnumerable) Console.WriteLine($"{row.Label}, {row.Features}"); @@ -47,7 +52,8 @@ public static void Example() // 1, 9 } - // Example with label and feature values. A data set is a collection of such examples. + // Example with label and feature values. A data set is a collection of such + // examples. private class DataPoint { public float Label { get; set; } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromText.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromText.cs index 9918b736ce..c61e9cff94 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromText.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SaveAndLoadFromText.cs @@ -9,9 +9,10 @@ public static class SaveAndLoadFromText { 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. @@ -24,10 +25,12 @@ public static void Example() new DataPoint(){ Label = 1, Features = 9}, }; - // 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. IDataView data = mlContext.Data.LoadFromEnumerable(dataPoints); - // Create a FileStream object and write the IDataView to it as a text file. + // Create a FileStream object and write the IDataView to it as a text + // file. using (FileStream stream = new FileStream("data.tsv", FileMode.Create)) mlContext.Data.SaveAsText(data, stream); @@ -35,7 +38,9 @@ public static void Example() IDataView loadedData = mlContext.Data.LoadFromTextFile("data.tsv"); // Inspect the data that is loaded from the previously saved text file. - var loadedDataEnumerable = mlContext.Data.CreateEnumerable(loadedData, reuseRowObject: false); + var loadedDataEnumerable = mlContext.Data + .CreateEnumerable(loadedData, reuseRowObject: false); + foreach (DataPoint row in loadedDataEnumerable) Console.WriteLine($"{row.Label}, {row.Features}"); @@ -47,7 +52,8 @@ public static void Example() // 1, 9 } - // Example with label and feature values. A data set is a collection of such examples. + // Example with label and feature values. A data set is a collection of such + // examples. private class DataPoint { public float Label { get; set; } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs index 2b786a7da4..3d77cc8d8d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs @@ -6,11 +6,13 @@ namespace Samples.Dynamic { public static class ShuffleRows { - // Sample class showing how to shuffle rows in IDataView. + // Sample class showing how to shuffle rows in + //IDataView. 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. + // 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -21,7 +23,8 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerableOfData) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}" + + $"\t{row.Temperature}"); } Console.WriteLine(); // Expected output: @@ -35,12 +38,17 @@ public static void Example() // Shuffle the dataset. var shuffledData = mlContext.Data.ShuffleRows(data, seed: 123); - // Look at the shuffled data and observe that the rows are in a randomized order. - var enumerable = mlContext.Data.CreateEnumerable(shuffledData, reuseRowObject: true); + // Look at the shuffled data and observe that the rows are in a + // randomized order. + var enumerable = mlContext.Data + .CreateEnumerable(shuffledData, + reuseRowObject: true); + Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerable) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}" + + $"\t{row.Temperature}"); } // Expected output: // Date Temperature @@ -62,7 +70,9 @@ private class SampleTemperatureData /// /// The number of examples to return. /// An enumerable of . - private static IEnumerable GetSampleTemperatureData(int exampleCount) + private static IEnumerable GetSampleTemperatureData( + int exampleCount) + { var rng = new Random(1234321); var date = new DateTime(2012, 1, 1); @@ -72,7 +82,9 @@ private static IEnumerable GetSampleTemperatureData(int e { date = date.AddDays(1); temperature += rng.Next(-5, 5); - yield return new SampleTemperatureData { Date = date, Temperature = temperature }; + yield return new SampleTemperatureData { Date = date, Temperature = + temperature }; + } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt index fa2adb3e9a..f76cadc6ae 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt @@ -3,9 +3,11 @@ string NameSpace = "Samples.Dynamic"; string ClassName="ShuffleRows"; string AddExtraClass = null; -string ExampleShortDoc = @"// Sample class showing how to shuffle rows in IDataView."; -string 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. +string ExampleShortDoc = @"// Sample class showing how to shuffle rows in + //IDataView."; +string 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -16,7 +18,8 @@ string Example = @"// Create a new context for ML.NET operations. It can be used Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerableOfData) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}"" + + $""\t{row.Temperature}""); } Console.WriteLine(); // Expected output: @@ -30,12 +33,17 @@ string Example = @"// Create a new context for ML.NET operations. It can be used // Shuffle the dataset. var shuffledData = mlContext.Data.ShuffleRows(data, seed: 123); - // Look at the shuffled data and observe that the rows are in a randomized order. - var enumerable = mlContext.Data.CreateEnumerable(shuffledData, reuseRowObject: true); + // Look at the shuffled data and observe that the rows are in a + // randomized order. + var enumerable = mlContext.Data + .CreateEnumerable(shuffledData, + reuseRowObject: true); + Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerable) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}"" + + $""\t{row.Temperature}""); } // Expected output: // Date Temperature diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs index cd1744a0f6..e19a223093 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs @@ -9,8 +9,9 @@ public static class SkipRows // Sample class showing how to skip rows in IDataView. 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. + // 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -21,7 +22,8 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerableOfData) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}" + + $"\t{row.Temperature}"); } Console.WriteLine(); // Expected output: @@ -40,12 +42,17 @@ public static void Example() // Skip the first 5 rows in the dataset var filteredData = mlContext.Data.SkipRows(data, 5); - // Look at the filtered data and observe that the first 5 rows have been dropped - var enumerable = mlContext.Data.CreateEnumerable(filteredData, reuseRowObject: true); + // Look at the filtered data and observe that the first 5 rows have been + // dropped + var enumerable = mlContext.Data + .CreateEnumerable(filteredData, + reuseRowObject: true); + Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerable) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}" + + $"\t{row.Temperature}"); } // Expected output: // Date Temperature @@ -67,7 +74,9 @@ private class SampleTemperatureData /// /// The number of examples to return. /// An enumerable of . - private static IEnumerable GetSampleTemperatureData(int exampleCount) + private static IEnumerable GetSampleTemperatureData( + int exampleCount) + { var rng = new Random(1234321); var date = new DateTime(2012, 1, 1); @@ -77,7 +86,9 @@ private static IEnumerable GetSampleTemperatureData(int e { date = date.AddDays(1); temperature += rng.Next(-5, 5); - yield return new SampleTemperatureData { Date = date, Temperature = temperature }; + yield return new SampleTemperatureData { Date = date, Temperature = + temperature }; + } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt index 411b4cf85a..ca43681241 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt @@ -4,8 +4,9 @@ string NameSpace = "Samples.Dynamic"; string ClassName="SkipRows"; string AddExtraClass = null; string ExampleShortDoc = @"// Sample class showing how to skip rows in IDataView."; -string 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. +string 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -16,7 +17,8 @@ string Example = @"// Create a new context for ML.NET operations. It can be used Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerableOfData) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}"" + + $""\t{row.Temperature}""); } Console.WriteLine(); // Expected output: @@ -35,12 +37,17 @@ string Example = @"// Create a new context for ML.NET operations. It can be used // Skip the first 5 rows in the dataset var filteredData = mlContext.Data.SkipRows(data, 5); - // Look at the filtered data and observe that the first 5 rows have been dropped - var enumerable = mlContext.Data.CreateEnumerable(filteredData, reuseRowObject: true); + // Look at the filtered data and observe that the first 5 rows have been + // dropped + var enumerable = mlContext.Data + .CreateEnumerable(filteredData, + reuseRowObject: true); + Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerable) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}"" + + $""\t{row.Temperature}""); } // Expected output: // Date Temperature diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs index 26a489f5e8..4e688e5d64 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs @@ -6,10 +6,12 @@ namespace Samples.Dynamic { public static class TakeRows { - // Sample class showing how to take some rows from the beginning of IDataView. + // Sample class showing how to take some rows from the + // beginning of IDataView. public static void Example() { - // Create a new context for ML.NET operations. It can be used for exception tracking and logging, + // 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. var mlContext = new MLContext(); @@ -21,7 +23,8 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerableOfData) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}" + + $"\t{row.Temperature}"); } Console.WriteLine(); // Expected output: @@ -40,12 +43,17 @@ public static void Example() // Take the first 5 rows in the dataset var filteredData = mlContext.Data.TakeRows(data, 5); - // Look at the filtered data and observe that only the first 5 rows are in the resulting dataset. - var enumerable = mlContext.Data.CreateEnumerable(filteredData, reuseRowObject: true); + // Look at the filtered data and observe that only the first 5 rows are + // in the resulting dataset. + var enumerable = mlContext.Data + .CreateEnumerable(filteredData, + reuseRowObject: true); + Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerable) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}" + + $"\t{row.Temperature}"); } // Expected output: // Date Temperature @@ -67,7 +75,9 @@ private class SampleTemperatureData /// /// The number of examples to return. /// An enumerable of . - private static IEnumerable GetSampleTemperatureData(int exampleCount) + private static IEnumerable GetSampleTemperatureData( + int exampleCount) + { var rng = new Random(1234321); var date = new DateTime(2012, 1, 1); @@ -77,7 +87,9 @@ private static IEnumerable GetSampleTemperatureData(int e { date = date.AddDays(1); temperature += rng.Next(-5, 5); - yield return new SampleTemperatureData { Date = date, Temperature = temperature }; + yield return new SampleTemperatureData { Date = date, Temperature = + temperature }; + } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt index 76f1edeb80..689f8df97d 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt @@ -3,20 +3,23 @@ string NameSpace = "Samples.Dynamic"; string ClassName="TakeRows"; string AddExtraClass = null; -string ExampleShortDoc = @"// Sample class showing how to take some rows from the beginning of IDataView."; -string Example = @"// Create a new context for ML.NET operations. It can be used for exception tracking and logging, +string ExampleShortDoc = @"// Sample class showing how to take some rows from the + // beginning of IDataView."; +string 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. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. - var enumerableOfData = Microsoft.ML.SamplesUtils.DatasetUtils.GetSampleTemperatureData(10); + var enumerableOfData = GetSampleTemperatureData(10); var data = mlContext.Data.LoadFromEnumerable(enumerableOfData); // Before we apply a filter, examine all the records in the dataset. Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerableOfData) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}"" + + $""\t{row.Temperature}""); } Console.WriteLine(); // Expected output: @@ -35,12 +38,17 @@ string Example = @"// Create a new context for ML.NET operations. It can be used // Take the first 5 rows in the dataset var filteredData = mlContext.Data.TakeRows(data, 5); - // Look at the filtered data and observe that only the first 5 rows are in the resulting dataset. - var enumerable = mlContext.Data.CreateEnumerable(filteredData, reuseRowObject: true); + // Look at the filtered data and observe that only the first 5 rows are + // in the resulting dataset. + var enumerable = mlContext.Data + .CreateEnumerable(filteredData, + reuseRowObject: true); + Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerable) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}"" + + $""\t{row.Temperature}""); } // Expected output: // Date Temperature diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TemperatureAndLatitude.ttinclude b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TemperatureAndLatitude.ttinclude index 448e743791..07ecca7ddf 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TemperatureAndLatitude.ttinclude +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TemperatureAndLatitude.ttinclude @@ -32,7 +32,9 @@ namespace <#=NameSpace#> /// /// The number of examples to return. /// An enumerable of . - private static IEnumerable GetSampleTemperatureData(int exampleCount) + private static IEnumerable GetSampleTemperatureData( + int exampleCount) + { var rng = new Random(1234321); var date = new DateTime(2012, 1, 1); @@ -42,7 +44,9 @@ namespace <#=NameSpace#> { date = date.AddDays(1); temperature += rng.Next(-5, 5); - yield return new SampleTemperatureData { Date = date, Temperature = temperature }; + yield return new SampleTemperatureData { Date = date, + Temperature = temperature }; + } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TrainTestSplit.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TrainTestSplit.cs index 47c56266bc..e4fc26296b 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TrainTestSplit.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TrainTestSplit.cs @@ -17,16 +17,26 @@ public static void Example() // Generate some data points. var examples = GenerateRandomDataPoints(10); - // Convert the examples list to an IDataView object, which is consumable by ML.NET API. + // Convert the examples list to an IDataView object, which is consumable + // by ML.NET API. var dataview = mlContext.Data.LoadFromEnumerable(examples); - // Leave out 10% of the dataset for testing.For some types of problems, for example for ranking or anomaly detection, - // we must ensure that the split leaves the rows with the same value in a particular column, in one of the splits. - // So below, we specify Group column as the column containing the sampling keys. - // Notice how keeping the rows with the same value in the Group column overrides the testFraction definition. - var split = mlContext.Data.TrainTestSplit(dataview, testFraction: 0.1, samplingKeyColumnName: "Group"); - var trainSet = mlContext.Data.CreateEnumerable(split.TrainSet, reuseRowObject: false); - var testSet = mlContext.Data.CreateEnumerable(split.TestSet, reuseRowObject: false); + // Leave out 10% of the dataset for testing.For some types of problems, + // for example for ranking or anomaly detection, we must ensure that the + // split leaves the rows with the same value in a particular column, in + // one of the splits. So below, we specify Group column as the column + // containing the sampling keys. Notice how keeping the rows with the + // same value in the Group column overrides the testFraction definition. + var split = mlContext.Data + .TrainTestSplit(dataview, testFraction: 0.1, + samplingKeyColumnName: "Group"); + + var trainSet = mlContext.Data + .CreateEnumerable(split.TrainSet, reuseRowObject: false); + + var testSet = mlContext.Data + .CreateEnumerable(split.TestSet,reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. @@ -45,8 +55,12 @@ public static void Example() // Example of a split without specifying a sampling key column. split = mlContext.Data.TrainTestSplit(dataview, testFraction: 0.2); - trainSet = mlContext.Data.CreateEnumerable(split.TrainSet, reuseRowObject: false); - testSet = mlContext.Data.CreateEnumerable(split.TestSet, reuseRowObject: false); + trainSet = mlContext.Data + .CreateEnumerable(split.TrainSet,reuseRowObject: false); + + testSet = mlContext.Data + .CreateEnumerable(split.TestSet,reuseRowObject: false); + PrintPreviewRows(trainSet, testSet); // The data in the Train split. @@ -65,7 +79,9 @@ public static void Example() } - private static IEnumerable GenerateRandomDataPoints(int count, int seed = 0) + private static IEnumerable GenerateRandomDataPoints(int count, + int seed = 0) + { var random = new Random(seed); for (int i = 0; i < count; i++) @@ -80,7 +96,8 @@ private static IEnumerable GenerateRandomDataPoints(int count, int se } } - // Example with label and group column. A data set is a collection of such examples. + // Example with label and group column. A data set is a collection of such + // examples. private class DataPoint { public float Group { get; set; } @@ -89,7 +106,9 @@ private class DataPoint } // print helper - private static void PrintPreviewRows(IEnumerable trainSet, IEnumerable testSet) + private static void PrintPreviewRows(IEnumerable trainSet, + IEnumerable testSet) + { Console.WriteLine($"The data in the Train split."); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs index 6137194558..67e9226ad6 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModel.cs @@ -25,8 +25,8 @@ public static void Example() var outputColumnName = nameof(Transformation.Key); // Transform. - ITransformer model = mlContext.Transforms.Conversion.MapValueToKey( - outputColumnName, inputColumnName).Fit(dataView); + ITransformer model = mlContext.Transforms.Conversion + .MapValueToKey(outputColumnName, inputColumnName).Fit(dataView); // Save model. mlContext.Model.Save(model, dataView.Schema, "model.zip"); @@ -36,8 +36,8 @@ public static void Example() model = mlContext.Model.Load(file, out DataViewSchema schema); // Create a prediction engine from the model for feeding new data. - var engine = mlContext.Model.CreatePredictionEngine(model); + var engine = mlContext.Model + .CreatePredictionEngine(model); var transformation = engine.Predict(new Data() { Value = "abc" }); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs index 60bb4a4a9f..88192cb3d3 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/ModelOperations/SaveLoadModelFile.cs @@ -25,8 +25,8 @@ public static void Example() var outputColumnName = nameof(Transformation.Key); // Transform. - ITransformer model = mlContext.Transforms.Conversion.MapValueToKey( - outputColumnName, inputColumnName).Fit(dataView); + ITransformer model = mlContext.Transforms.Conversion + .MapValueToKey(outputColumnName, inputColumnName).Fit(dataView); // Save model. mlContext.Model.Save(model, dataView.Schema, "model.zip"); @@ -35,8 +35,8 @@ public static void Example() model = mlContext.Model.Load("model.zip", out DataViewSchema schema); // Create a prediction engine from the model for feeding new data. - var engine = mlContext.Model.CreatePredictionEngine(model); + var engine = mlContext.Model + .CreatePredictionEngine(model); var transformation = engine.Predict(new Data() { Value = "abc" }); From 10f40fd13ebe8f30718b28fcfea71a02c5375d76 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 05:42:31 -0700 Subject: [PATCH 04/27] Update docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs Co-Authored-By: Justin Ormont --- .../Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs index b1e73977bb..09855b2d07 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/Cache.cs @@ -20,7 +20,7 @@ public static void Example() TimeToScanIDataView(mlContext, data); Console.WriteLine($"Lines={lines}," + - $"averageOfColumn0={columnAverage:0.00}and took {elapsedSeconds}" + + $"averageOfColumn0={columnAverage:0.00} and took {elapsedSeconds}" + $"seconds."); // Expected output (time is approximate): // Lines=506, averageOfColumn0=564.17 and took 0.314 seconds. @@ -101,4 +101,4 @@ public sealed class HousingRegression } } -} \ No newline at end of file +} From 00acf2ad706fd3c4086f70563bfc437857811b99 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 08:36:55 -0700 Subject: [PATCH 05/27] Update Program.cs Got rid of test comment --- docs/samples/Microsoft.ML.Samples/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Program.cs b/docs/samples/Microsoft.ML.Samples/Program.cs index 333a331286..eb49938927 100644 --- a/docs/samples/Microsoft.ML.Samples/Program.cs +++ b/docs/samples/Microsoft.ML.Samples/Program.cs @@ -9,7 +9,6 @@ public static class Program internal static void RunAll() { - // Samples counter. int samples = 0; foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { From acdf665cfb79212af92e2092f36772d9f31d9923 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 10:58:31 -0700 Subject: [PATCH 06/27] Update DataViewEnumerable.tt Fixed extra whitespace --- .../Dynamic/DataOperations/DataViewEnumerable.tt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt index 6618e2b9cc..8443c900cd 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt @@ -18,7 +18,7 @@ string Example = @"// Create a new context for ML.NET operations. It can be used IDataView data = mlContext.Data.LoadFromEnumerable(enumerableOfData); // We can now examine the records in the IDataView. We first create an - // enumerable of rows in the IDataView. + // enumerable of rows in the IDataView. var rowEnumerable = mlContext.Data .CreateEnumerable(data, reuseRowObject: true); @@ -57,4 +57,4 @@ string Example = @"// Create a new context for ML.NET operations. It can be used // 1/4/2012 34 0 // 1/5/2012 35 0 // 1/6/2012 35 0"; -#> \ No newline at end of file +#> From 842765fa6b6c6664c36eb2301db85a0a65b12528 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:04:02 -0700 Subject: [PATCH 07/27] Update DataViewEnumerable.cs Fixed extra whitespace --- .../Dynamic/DataOperations/DataViewEnumerable.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs index 239c998e4b..567d1f9a3c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs @@ -11,7 +11,7 @@ public static class DataViewEnumerable public static void Example() { // Create a new context for ML.NET operations. It can be used for - // exception tracking and logging, + // exception tracking and logging, // as a catalog of available operations and as the source of randomness. var mlContext = new MLContext(); @@ -29,10 +29,10 @@ public static void Example() reuseRowObject: true); // SampleTemperatureDataWithLatitude has the definition of a Latitude - // column of type float. We can use the parameter ignoreMissingColumns - // to true to ignore any missing columns in the IDataView. The produced - // enumerable will have the Latitude field set to the default for the - // data type, in this case 0. + // column of type float. We can use the parameter ignoreMissingColumns + // to true to ignore any missing columns in the IDataView. The produced + // enumerable will have the Latitude field set to the default for the + // data type, in this case 0. var rowEnumerableIgnoreMissing = mlContext.Data .CreateEnumerable(data, reuseRowObject: true, ignoreMissingColumns: true); From fe9c1888dd8ed7ad759d42ca4dfb11ed0bb21194 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:11:17 -0700 Subject: [PATCH 08/27] Update DataViewEnumerable.tt Fixed extra whitespace --- .../Dynamic/DataOperations/DataViewEnumerable.tt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt index 8443c900cd..ebcce161ff 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.tt @@ -24,10 +24,10 @@ string Example = @"// Create a new context for ML.NET operations. It can be used reuseRowObject: true); // SampleTemperatureDataWithLatitude has the definition of a Latitude - // column of type float. We can use the parameter ignoreMissingColumns - // to true to ignore any missing columns in the IDataView. The produced - // enumerable will have the Latitude field set to the default for the - // data type, in this case 0. + // column of type float. We can use the parameter ignoreMissingColumns + // to true to ignore any missing columns in the IDataView. The produced + // enumerable will have the Latitude field set to the default for the + // data type, in this case 0. var rowEnumerableIgnoreMissing = mlContext.Data .CreateEnumerable(data, reuseRowObject: true, ignoreMissingColumns: true); From 2f91a6dc32de5992668a24248b86ac85f33c8620 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:16:21 -0700 Subject: [PATCH 09/27] Update FilterRowsByColumn.tt Fixed whitespace --- .../Dynamic/DataOperations/FilterRowsByColumn.tt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt index 8e63e59679..0071cc3242 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt @@ -7,7 +7,7 @@ string ExampleShortDoc = @"// // Sample class showing how to filter out some row // IDataView."; string 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. + // operations and as the source of randomness. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -37,13 +37,13 @@ string Example = @"// Create a new context for ML.NET operations. It can be used // 1/11/2012 29 // Filter the data by the values of the temperature. The lower bound is - // inclusive, the upper exclusive. + // inclusive, the upper exclusive. var filteredData = mlContext.Data .FilterRowsByColumn(data, columnName: ""Temperature"", lowerBound: 34, upperBound: 37); // Look at the filtered data and observe that values outside [34,37) - // have been dropped. + // have been dropped. var enumerable = mlContext.Data .CreateEnumerable(filteredData, reuseRowObject: true); From 7a27578a101bc5529a1e16dfd40434ce280cbeb5 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:17:16 -0700 Subject: [PATCH 10/27] Update ShuffleRows.tt Fixed whitespace --- .../Dynamic/DataOperations/ShuffleRows.tt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt index f76cadc6ae..e5d22be65f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt @@ -7,7 +7,7 @@ string ExampleShortDoc = @"// Sample class showing how to shuffle rows in //IDataView."; string 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. + // and as the source of randomness. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. @@ -34,7 +34,7 @@ string Example = @"// Create a new context for ML.NET operations. It can be used var shuffledData = mlContext.Data.ShuffleRows(data, seed: 123); // Look at the shuffled data and observe that the rows are in a - // randomized order. + // randomized order. var enumerable = mlContext.Data .CreateEnumerable(shuffledData, reuseRowObject: true); From cd05ce00c048ed7e23c42d4d96ee0886e372cda7 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:18:15 -0700 Subject: [PATCH 11/27] Update TakeRows.tt Fixed whitespace --- .../Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt index 689f8df97d..1e482591db 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.tt @@ -39,7 +39,7 @@ string Example = @"// Create a new context for ML.NET operations. It can be used var filteredData = mlContext.Data.TakeRows(data, 5); // Look at the filtered data and observe that only the first 5 rows are - // in the resulting dataset. + // in the resulting dataset. var enumerable = mlContext.Data .CreateEnumerable(filteredData, reuseRowObject: true); From 61de1fb5c00b1549afcfb97acab2d65372646e6f Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:19:57 -0700 Subject: [PATCH 12/27] Update TakeRows.cs Fixed whitespace --- .../Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs index 4e688e5d64..5ad6f13f7f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/TakeRows.cs @@ -44,7 +44,7 @@ public static void Example() var filteredData = mlContext.Data.TakeRows(data, 5); // Look at the filtered data and observe that only the first 5 rows are - // in the resulting dataset. + // in the resulting dataset. var enumerable = mlContext.Data .CreateEnumerable(filteredData, reuseRowObject: true); From 5d2e8af85c6a52323108f8e00260b18096236621 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:21:59 -0700 Subject: [PATCH 13/27] Update SkipRows.cs Fixed whitespace --- .../Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs index e19a223093..fa9baef7a4 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs @@ -11,7 +11,7 @@ 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. + // and as the source of randomness. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. From 063a651882054be3c5b8a21fae7bb327c369de15 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:23:00 -0700 Subject: [PATCH 14/27] Update SkipRows.tt Fixed whitespace --- .../Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt index ca43681241..e5a81769dd 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt @@ -6,7 +6,7 @@ string AddExtraClass = null; string ExampleShortDoc = @"// Sample class showing how to skip rows in IDataView."; string 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. + // and as the source of randomness. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. From 958633bd00acca1b4af3fa30ce3fd3ad6eb07e61 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:24:58 -0700 Subject: [PATCH 15/27] Update ShuffleRows.cs Fixed whitespace --- .../Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs index 3d77cc8d8d..597428a2d0 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs @@ -12,7 +12,7 @@ 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. + // and as the source of randomness. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. From 01a539072e7ccf4b8d87aacb8feb84e5e453e7e7 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:25:42 -0700 Subject: [PATCH 16/27] Update ShuffleRows.cs Fixed whitespace --- .../Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs index 597428a2d0..88fef392ab 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs @@ -39,7 +39,7 @@ public static void Example() var shuffledData = mlContext.Data.ShuffleRows(data, seed: 123); // Look at the shuffled data and observe that the rows are in a - // randomized order. + // randomized order. var enumerable = mlContext.Data .CreateEnumerable(shuffledData, reuseRowObject: true); From 0eb6065971a8b7139514abfa4d8bd8f45d2b1177 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:27:08 -0700 Subject: [PATCH 17/27] Update ShuffleRows.cs --- .../Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs index 88fef392ab..73ef6657e1 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.cs @@ -7,7 +7,7 @@ namespace Samples.Dynamic public static class ShuffleRows { // Sample class showing how to shuffle rows in - //IDataView. + // IDataView. public static void Example() { // Create a new context for ML.NET operations. It can be used for From 2db2bde6ae9af1d42713f68edd69fec3d9357c83 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:27:26 -0700 Subject: [PATCH 18/27] Update ShuffleRows.tt --- .../Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt index e5d22be65f..4c77c521a9 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/ShuffleRows.tt @@ -4,7 +4,7 @@ string NameSpace = "Samples.Dynamic"; string ClassName="ShuffleRows"; string AddExtraClass = null; string ExampleShortDoc = @"// Sample class showing how to shuffle rows in - //IDataView."; + // IDataView."; string 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. From 8c1989f5550f9174943804b878d622c90885c378 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:29:34 -0700 Subject: [PATCH 19/27] Update SkipRows.tt --- .../Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt index e5a81769dd..59bd97c443 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.tt @@ -38,7 +38,7 @@ string Example = @"// Create a new context for ML.NET operations. It can be used var filteredData = mlContext.Data.SkipRows(data, 5); // Look at the filtered data and observe that the first 5 rows have been - // dropped + // dropped var enumerable = mlContext.Data .CreateEnumerable(filteredData, reuseRowObject: true); From f39823ac7f586fa53e2aa39bd44cdb343eecc9ea Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:30:06 -0700 Subject: [PATCH 20/27] Update SkipRows.cs --- .../Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs index fa9baef7a4..006082f238 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/SkipRows.cs @@ -43,7 +43,7 @@ public static void Example() var filteredData = mlContext.Data.SkipRows(data, 5); // Look at the filtered data and observe that the first 5 rows have been - // dropped + // dropped var enumerable = mlContext.Data .CreateEnumerable(filteredData, reuseRowObject: true); From 90ed0607a8963176b3a1a8b2fbd90a2e0387a2e2 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:33:16 -0700 Subject: [PATCH 21/27] Update FilterRowsByColumn.cs Fixed whitespace --- .../Dynamic/DataOperations/FilterRowsByColumn.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs index b6b1d9ead7..c682e73682 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs @@ -42,13 +42,13 @@ public static void Example() // 1/11/2012 29 // Filter the data by the values of the temperature. The lower bound is - // inclusive, the upper exclusive. + // inclusive, the upper exclusive. var filteredData = mlContext.Data .FilterRowsByColumn(data, columnName: "Temperature", lowerBound: 34, upperBound: 37); // Look at the filtered data and observe that values outside [34,37) - // have been dropped. + // have been dropped. var enumerable = mlContext.Data .CreateEnumerable(filteredData, reuseRowObject: true); From 2a5e8c3e40e77f1e39fec884daaef30d94da4cbb Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:34:22 -0700 Subject: [PATCH 22/27] Update FilterRowsByColumn.cs Fixed whitespace --- .../Dynamic/DataOperations/FilterRowsByColumn.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs index c682e73682..b4385af0e7 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs @@ -12,7 +12,7 @@ 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. + // operations and as the source of randomness. var mlContext = new MLContext(); // Get a small dataset as an IEnumerable. From f9d91e6dabfd7a03d47b5d4779f4741becf2818d Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 11:40:00 -0700 Subject: [PATCH 23/27] Update DataViewEnumerable.cs --- .../Dynamic/DataOperations/DataViewEnumerable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs index 567d1f9a3c..aaefc85597 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/DataViewEnumerable.cs @@ -23,7 +23,7 @@ public static void Example() IDataView data = mlContext.Data.LoadFromEnumerable(enumerableOfData); // We can now examine the records in the IDataView. We first create an - // enumerable of rows in the IDataView. + // enumerable of rows in the IDataView. var rowEnumerable = mlContext.Data .CreateEnumerable(data, reuseRowObject: true); From 5daecb80d0bae81172828a4ce0bc0a5e1db411b5 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 13:23:37 -0700 Subject: [PATCH 24/27] Update FilterRowsByColumn.cs Fixed extra carriage returns --- .../Dynamic/DataOperations/FilterRowsByColumn.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs index b4385af0e7..a7dcc23045 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs @@ -23,8 +23,7 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerableOfData) { - Console.WriteLine( - $"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); } Console.WriteLine(); @@ -45,7 +44,7 @@ public static void Example() // inclusive, the upper exclusive. var filteredData = mlContext.Data .FilterRowsByColumn(data, columnName: "Temperature", - lowerBound: 34, upperBound: 37); + lowerBound: 34, upperBound: 37); // Look at the filtered data and observe that values outside [34,37) // have been dropped. @@ -56,8 +55,7 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerable) { - Console.WriteLine( - $"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); } From c436498e102ffa62e414de34713688ea3e5e4f41 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 13:24:51 -0700 Subject: [PATCH 25/27] Update FilterRowsByColumn.tt Fixed extra carriage returns --- .../Dynamic/DataOperations/FilterRowsByColumn.tt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt index 0071cc3242..e6090b8f4c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt @@ -18,8 +18,7 @@ string Example = @"// Create a new context for ML.NET operations. It can be used Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerableOfData) { - Console.WriteLine( - $""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); } Console.WriteLine(); @@ -51,8 +50,7 @@ string Example = @"// Create a new context for ML.NET operations. It can be used Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerable) { - Console.WriteLine( - $""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); } From 49d7a092269de5a65179530e4df287612d9a0504 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 14:43:11 -0700 Subject: [PATCH 26/27] Update FilterRowsByColumn.cs --- .../Dynamic/DataOperations/FilterRowsByColumn.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs index a7dcc23045..af6df27200 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.cs @@ -23,7 +23,8 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerableOfData) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine( + $"{row.Date.ToString("d")}\t{row.Temperature}"); } Console.WriteLine(); @@ -55,7 +56,8 @@ public static void Example() Console.WriteLine($"Date\tTemperature"); foreach (var row in enumerable) { - Console.WriteLine($"{row.Date.ToString("d")}\t{row.Temperature}"); + Console.WriteLine( + $"{row.Date.ToString("d")}\t{row.Temperature}"); } From d2315f91924ed7aee8e5c2a41027e3cc220c30b7 Mon Sep 17 00:00:00 2001 From: Sierra Lee Date: Fri, 28 Jun 2019 14:43:48 -0700 Subject: [PATCH 27/27] Update FilterRowsByColumn.tt --- .../Dynamic/DataOperations/FilterRowsByColumn.tt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt index e6090b8f4c..878cc2eb9e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/DataOperations/FilterRowsByColumn.tt @@ -50,7 +50,8 @@ string Example = @"// Create a new context for ML.NET operations. It can be used Console.WriteLine($""Date\tTemperature""); foreach (var row in enumerable) { - Console.WriteLine($""{row.Date.ToString(""d"")}\t{row.Temperature}""); + Console.WriteLine( + $""{row.Date.ToString(""d"")}\t{row.Temperature}""); }