33// See the LICENSE file in the project root for more information.
44
55using System ;
6- using System . Collections . Generic ;
76using System . IO ;
8- using System . Linq ;
97using Microsoft . Data . DataView ;
108using Microsoft . ML ;
119using Microsoft . ML . Auto ;
@@ -19,40 +17,40 @@ static class AutoTrainRegression
1917 private static string TrainDataPath = $ "{ BaseDatasetsLocation } /taxi-fare-train.csv";
2018 private static string TestDataPath = $ "{ BaseDatasetsLocation } /taxi-fare-test.csv";
2119 private static string ModelPath = $ "{ BaseDatasetsLocation } /TaxiFareModel.zip";
22- private static string LabelColumnName = "fare_amount" ;
20+ private static string LabelColumn = "fare_amount" ;
2321
2422 public static void Run ( )
2523 {
2624 MLContext mlContext = new MLContext ( ) ;
2725
28- // STEP 1: Common data loading configuration
29- var columnInference = mlContext . AutoInference ( ) . InferColumns ( TrainDataPath , LabelColumnName ) ;
26+ // STEP 1: Infer columns
27+ var columnInference = mlContext . AutoInference ( ) . InferColumns ( TrainDataPath , LabelColumn ) ;
3028
3129 // STEP 2: Load data
3230 TextLoader textLoader = mlContext . Data . CreateTextLoader ( columnInference . TextLoaderArgs ) ;
3331 IDataView trainDataView = textLoader . Read ( TrainDataPath ) ;
3432 IDataView testDataView = textLoader . Read ( TestDataPath ) ;
3533
36- // STEP 3: Auto featurize, auto train and auto hyperparameter tuning
37- Console . WriteLine ( $ "Invoking Regression.AutoFit ") ;
38- var autoFitResults = mlContext . AutoInference ( )
34+ // STEP 3: Auto featurize, auto train and auto hyperparameter tune
35+ Console . WriteLine ( $ "Invoking new AutoML regression experiment... ") ;
36+ var runResults = mlContext . AutoInference ( )
3937 . CreateRegressionExperiment ( 0 )
40- . Execute ( trainDataView , LabelColumnName ) ;
38+ . Execute ( trainDataView , LabelColumn ) ;
4139
42- // STEP 4: Compare and print actual value vs predicted value for top 5 rows from validation data
43- var best = autoFitResults . Best ( ) ;
40+ // STEP 4: Print metric from best model
41+ var best = runResults . Best ( ) ;
4442 Console . WriteLine ( $ "RSquared of best model from validation data: { best . Metrics . RSquared } ") ;
4543
4644 // STEP 5: Evaluate test data
4745 IDataView testDataViewWithBestScore = best . Model . Transform ( testDataView ) ;
48- var testMetrics = mlContext . Regression . Evaluate ( testDataViewWithBestScore , label : LabelColumnName , DefaultColumnNames . Score ) ;
49- Console . WriteLine ( $ "RSquared of best model from test data: { best . Metrics . RSquared } ") ;
46+ var testMetrics = mlContext . Regression . Evaluate ( testDataViewWithBestScore , label : LabelColumn ) ;
47+ Console . WriteLine ( $ "RSquared of best model on test data: { best . Metrics . RSquared } ") ;
5048
5149 // STEP 6: Save the best model for later deployment and inferencing
5250 using ( var fs = File . Create ( ModelPath ) )
5351 best . Model . SaveTo ( mlContext , fs ) ;
5452
55- Console . WriteLine ( "Press any key to continue.." ) ;
53+ Console . WriteLine ( "Press any key to continue... " ) ;
5654 Console . ReadLine ( ) ;
5755 }
5856 }
0 commit comments