@@ -30,22 +30,24 @@ public static void Run()
30
30
. Execute ( trainDataView , LabelColumnName ) ;
31
31
32
32
// STEP 3: Print metric from the best model
33
- RunDetail < MulticlassClassificationMetrics > best = experimentResult . BestRun ;
33
+ RunDetail < MulticlassClassificationMetrics > bestRun = experimentResult . BestRun ;
34
34
Console . WriteLine ( $ "Total models produced: { experimentResult . RunDetails . Count ( ) } ") ;
35
- Console . WriteLine ( $ "Best model's trainer: { best . TrainerName } ") ;
36
- Console . WriteLine ( $ "MicroAccuracy of best model from validation data: { best . ValidationMetrics . MicroAccuracy } ") ;
35
+ Console . WriteLine ( $ "Best model's trainer: { bestRun . TrainerName } ") ;
36
+ Console . WriteLine ( $ "Metrics of best model from validation data --") ;
37
+ PrintMetrics ( bestRun . ValidationMetrics ) ;
37
38
38
39
// STEP 4: Evaluate test data
39
- IDataView testDataViewWithBestScore = best . Model . Transform ( testDataView ) ;
40
+ IDataView testDataViewWithBestScore = bestRun . Model . Transform ( testDataView ) ;
40
41
MulticlassClassificationMetrics testMetrics = mlContext . MulticlassClassification . Evaluate ( testDataViewWithBestScore , labelColumnName : LabelColumnName ) ;
41
- Console . WriteLine ( $ "MicroAccuracy of best model on test data: { testMetrics . MicroAccuracy } ") ;
42
+ Console . WriteLine ( $ "MicroAccuracy of best model on test data") ;
43
+ PrintMetrics ( testMetrics ) ;
42
44
43
45
// STEP 5: Save the best model for later deployment and inferencing
44
46
using ( FileStream fs = File . Create ( ModelPath ) )
45
- mlContext . Model . Save ( best . Model , trainDataView . Schema , fs ) ;
47
+ mlContext . Model . Save ( bestRun . Model , trainDataView . Schema , fs ) ;
46
48
47
49
// STEP 6: Create prediction engine from the best trained model
48
- var predictionEngine = mlContext . Model . CreatePredictionEngine < PixelData , PixelPrediction > ( best . Model ) ;
50
+ var predictionEngine = mlContext . Model . CreatePredictionEngine < PixelData , PixelPrediction > ( bestRun . Model ) ;
49
51
50
52
// STEP 7: Initialize new pixel data, and get the predicted number
51
53
var testPixelData = new PixelData
@@ -58,5 +60,16 @@ public static void Run()
58
60
Console . WriteLine ( "Press any key to continue..." ) ;
59
61
Console . ReadKey ( ) ;
60
62
}
63
+
64
+ private static void PrintMetrics ( MulticlassClassificationMetrics metrics )
65
+ {
66
+ Console . WriteLine ( $ "LogLoss: { metrics . LogLoss } ") ;
67
+ Console . WriteLine ( $ "LogLossReduction: { metrics . LogLossReduction } ") ;
68
+ Console . WriteLine ( $ "MacroAccuracy: { metrics . MacroAccuracy } ") ;
69
+ Console . WriteLine ( $ "MicroAccuracy: { metrics . MicroAccuracy } ") ;
70
+ Console . WriteLine ( $ "PerClassLogLoss: { metrics . PerClassLogLoss } ") ;
71
+ Console . WriteLine ( $ "TopKAccuracy: { metrics . TopKAccuracy } ") ;
72
+ Console . WriteLine ( $ "TopKPredictionCount: { metrics . TopKPredictionCount } ") ;
73
+ }
61
74
}
62
75
}
0 commit comments