11using System ;
22using System . Collections . Generic ;
3- using System . IO ;
43using System . Linq ;
5- using System . Security . Cryptography ;
6- using System . Security . Cryptography . X509Certificates ;
74using Microsoft . ML ;
85using Microsoft . ML . Data ;
96
@@ -12,10 +9,10 @@ namespace Samples.Dynamic.Trainers.Regression
129 public static class FastTreeRegression
1310 {
1411 // This example requires installation of additional NuGet package
15- // <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>.
12+ // <a href="https://www.nuget.org/packages/Microsoft.ML.FastTree/">Microsoft.ML.FastTree</a>.
1613 public static void Example ( )
1714 {
18- // Create a new context for ML.NET operations. It can be used for exception tracking and logging,
15+ // Create a new context for ML.NET operations. It can be used for exception tracking and logging,
1916 // as a catalog of available operations and as the source of randomness.
2017 // Setting the seed to a fixed number in this example to make outputs deterministic.
2118 var mlContext = new MLContext ( seed : 0 ) ;
@@ -26,25 +23,17 @@ public static void Example()
2623 // Convert the list of data points to an IDataView object, which is consumable by ML.NET API.
2724 var trainingData = mlContext . Data . LoadFromEnumerable ( dataPoints ) ;
2825
29- using ( var f = File . OpenWrite ( "E:\\ tmp\\ data.txt" ) )
30- mlContext . Data . SaveAsText ( trainingData , f ) ;
31-
3226 // Define the trainer.
33-
34- var pipeline = mlContext . Data . CreateTextLoader < DataPoint > ( hasHeader : true )
35- . Append ( mlContext . Regression . Trainers . FastTree ( labelColumnName : nameof ( DataPoint . Label ) ,
36- featureColumnName : nameof ( DataPoint . Features ) ) ) ;
27+ var pipeline = mlContext . Regression . Trainers . FastTree ( labelColumnName : nameof ( DataPoint . Label ) , featureColumnName : nameof ( DataPoint . Features ) ) ;
3728
3829 // Train the model.
39- var model = pipeline . Fit ( new MultiFileSource ( new [ ] { "E:\\ tmp\\ data.txt" } ) ) ;
40-
41- mlContext . Model . Save ( model . Transformer , model . Loader , "E:\\ tmp\\ model.bin" ) ;
30+ var model = pipeline . Fit ( trainingData ) ;
4231
4332 // Create testing data. Use different random seed to make it different from training data.
4433 var testData = mlContext . Data . LoadFromEnumerable ( GenerateRandomDataPoints ( 5 , seed : 123 ) ) ;
4534
4635 // Run the model on test data set.
47- var transformedTestData = model . Transformer . Transform ( testData ) ;
36+ var transformedTestData = model . Transform ( testData ) ;
4837
4938 // Convert IDataView object to a list.
5039 var predictions = mlContext . Data . CreateEnumerable < Prediction > ( transformedTestData , reuseRowObject : false ) . ToList ( ) ;
@@ -89,10 +78,7 @@ private static IEnumerable<DataPoint> GenerateRandomDataPoints(int count, int se
8978 // Example with label and 50 feature values. A data set is a collection of such examples.
9079 private class DataPoint
9180 {
92- [ LoadColumn ( 0 ) ]
9381 public float Label { get ; set ; }
94-
95- [ LoadColumn ( 1 , 50 ) ]
9682 [ VectorType ( 50 ) ]
9783 public float [ ] Features { get ; set ; }
9884 }
0 commit comments