Skip to content

Commit 9faceb2

Browse files
authored
Formatting Regression metrics and progress bar display days. (dotnet#379)
* added progress bar day display and fix regression metrics * fix formatting * added total time * formatted total time
1 parent 40496fd commit 9faceb2

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/mlnet/CodeGenerator/CodeGenerationHelper.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.IO;
89
using System.Linq;
910
using System.Runtime.ExceptionServices;
@@ -36,6 +37,7 @@ public CodeGenerationHelper(IAutoMLEngine automlEngine, NewCommandSettings setti
3637

3738
public void GenerateCode()
3839
{
40+
Stopwatch watch = Stopwatch.StartNew();
3941
var context = new MLContext();
4042

4143
// Infer columns
@@ -92,6 +94,7 @@ public void GenerateCode()
9294
};
9395
var wait = TimeSpan.FromSeconds(settings.MaxExplorationTime);
9496
var verboseLevel = Utils.GetVerbosity(settings.Verbosity);
97+
9598
if (verboseLevel > LogLevel.Trace && !Console.IsOutputRedirected)
9699
{
97100
using (var pbar = new FixedDurationBar(wait, "", options))
@@ -163,6 +166,8 @@ public void GenerateCode()
163166
return;
164167
}
165168

169+
var elapsedTime = watch.Elapsed.TotalSeconds;
170+
166171
//Get the best pipeline
167172
Pipeline bestPipeline = null;
168173
ITransformer bestModel = null;
@@ -173,21 +178,21 @@ public void GenerateCode()
173178
var bestBinaryIteration = binaryRunDetails.Best();
174179
bestPipeline = bestBinaryIteration.Pipeline;
175180
bestModel = bestBinaryIteration.Model;
176-
ConsolePrinter.ExperimentResultsHeader(LogLevel.Info, settings.MlTask, settings.Dataset.Name, columnInformation.LabelColumnName, settings.MaxExplorationTime.ToString(), binaryRunDetails.Count());
181+
ConsolePrinter.ExperimentResultsHeader(LogLevel.Info, settings.MlTask, settings.Dataset.Name, columnInformation.LabelColumnName, elapsedTime.ToString("F2"), binaryRunDetails.Count());
177182
ConsolePrinter.PrintIterationSummary(binaryRunDetails, new BinaryExperimentSettings().OptimizingMetric, 5);
178183
break;
179184
case TaskKind.Regression:
180185
var bestRegressionIteration = regressionRunDetails.Best();
181186
bestPipeline = bestRegressionIteration.Pipeline;
182187
bestModel = bestRegressionIteration.Model;
183-
ConsolePrinter.ExperimentResultsHeader(LogLevel.Info, settings.MlTask, settings.Dataset.Name, columnInformation.LabelColumnName, settings.MaxExplorationTime.ToString(), regressionRunDetails.Count());
188+
ConsolePrinter.ExperimentResultsHeader(LogLevel.Info, settings.MlTask, settings.Dataset.Name, columnInformation.LabelColumnName, elapsedTime.ToString("F2"), regressionRunDetails.Count());
184189
ConsolePrinter.PrintIterationSummary(regressionRunDetails, new RegressionExperimentSettings().OptimizingMetric, 5);
185190
break;
186191
case TaskKind.MulticlassClassification:
187192
var bestMultiIteration = multiRunDetails.Best();
188193
bestPipeline = bestMultiIteration.Pipeline;
189194
bestModel = bestMultiIteration.Model;
190-
ConsolePrinter.ExperimentResultsHeader(LogLevel.Info, settings.MlTask, settings.Dataset.Name, columnInformation.LabelColumnName, settings.MaxExplorationTime.ToString(), multiRunDetails.Count());
195+
ConsolePrinter.ExperimentResultsHeader(LogLevel.Info, settings.MlTask, settings.Dataset.Name, columnInformation.LabelColumnName, elapsedTime.ToString("F2"), multiRunDetails.Count());
191196
ConsolePrinter.PrintIterationSummary(multiRunDetails, new MulticlassExperimentSettings().OptimizingMetric, 5);
192197
break;
193198
}

src/mlnet/ProgressBar/ProgressBar.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ private static void ProgressBarBottomHalf(double percentage, DateTime startDate,
110110
var depth = indentation.Length;
111111
var maxCharacterWidth = Console.WindowWidth - (depth * 2) + 2;
112112
var duration = ((endDate ?? DateTime.Now) - startDate);
113-
var durationString = $"{duration.Hours:00}:{duration.Minutes:00}:{duration.Seconds:00}";
113+
string durationString = null;
114+
if (duration.Days > 0)
115+
durationString = $"{duration.Days:00}:{duration.Hours:00}:{duration.Minutes:00}:{duration.Seconds:00}";
116+
else
117+
durationString = $"{duration.Hours:00}:{duration.Minutes:00}:{duration.Seconds:00}";
114118

115119
var column1Width = Console.WindowWidth - durationString.Length - (depth * 2) + 2;
116120
var column2Width = durationString.Length;

src/mlnet/Utilities/ConsolePrinter.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ internal class ConsolePrinter
1919

2020
internal static void PrintMetrics(int iteration, string trainerName, BinaryClassificationMetrics metrics, double bestMetric, double? runtimeInSeconds, LogLevel logLevel, int iterationNumber = -1)
2121
{
22-
logger.Log(logLevel, CreateRow($"{iteration,-4} {trainerName,-35} {metrics?.Accuracy ?? double.NaN,9:F4} {metrics?.AreaUnderRocCurve ?? double.NaN,8:F4} {metrics?.AreaUnderPrecisionRecallCurve ?? double.NaN,8:F4} {metrics?.F1Score ?? double.NaN,9:F4} {runtimeInSeconds.Value,9:F1} {iterationNumber + 1,9}", Width));
22+
logger.Log(logLevel, CreateRow($"{iteration,-4} {trainerName,-35} {metrics?.Accuracy ?? double.NaN,9:F4} {metrics?.AreaUnderRocCurve ?? double.NaN,8:F4} {metrics?.AreaUnderPrecisionRecallCurve ?? double.NaN,8:F4} {metrics?.F1Score ?? double.NaN,9:F4} {runtimeInSeconds.Value,9:F1} {iterationNumber + 1,10}", Width));
2323
}
2424

2525
internal static void PrintMetrics(int iteration, string trainerName, MulticlassClassificationMetrics metrics, double bestMetric, double? runtimeInSeconds, LogLevel logLevel, int iterationNumber = -1)
2626
{
27-
logger.Log(logLevel, CreateRow($"{iteration,-4} {trainerName,-35} {metrics?.MicroAccuracy ?? double.NaN,14:F4} {metrics?.MacroAccuracy ?? double.NaN,14:F4} {runtimeInSeconds.Value,9:F1} {iterationNumber + 1,9}", Width));
27+
logger.Log(logLevel, CreateRow($"{iteration,-4} {trainerName,-35} {metrics?.MicroAccuracy ?? double.NaN,14:F4} {metrics?.MacroAccuracy ?? double.NaN,14:F4} {runtimeInSeconds.Value,9:F1} {iterationNumber + 1,10}", Width));
2828
}
2929

3030
internal static void PrintMetrics(int iteration, string trainerName, RegressionMetrics metrics, double bestMetric, double? runtimeInSeconds, LogLevel logLevel, int iterationNumber = -1)
3131
{
32-
logger.Log(logLevel, CreateRow($"{iteration,-4} {trainerName,-35} {metrics?.RSquared ?? double.NaN,9:F4} {metrics?.LossFunction ?? double.NaN,12:F2} {metrics?.MeanAbsoluteError ?? double.NaN,15:F2} {metrics?.MeanSquaredError ?? double.NaN,15:F2} {metrics?.RootMeanSquaredError ?? double.NaN,12:F2} {runtimeInSeconds.Value,9:F1} {iterationNumber + 1,9}", Width));
32+
logger.Log(logLevel, CreateRow($"{iteration,-4} {trainerName,-35} {metrics?.RSquared ?? double.NaN,8:F4} {metrics?.MeanAbsoluteError ?? double.NaN,13:F2} {metrics?.MeanSquaredError ?? double.NaN,12:F2} {metrics?.RootMeanSquaredError ?? double.NaN,8:F2} {runtimeInSeconds.Value,9:F1} {iterationNumber + 1,10}", Width));
3333
}
3434

3535
internal static void PrintBinaryClassificationMetricsHeader(LogLevel logLevel)
3636
{
37-
logger.Log(logLevel, CreateRow($"{"",-4} {"Trainer",-35} {"Accuracy",9} {"AUC",8} {"AUPRC",8} {"F1-score",9} {"Duration",9} {"#Iteration",9}", Width));
37+
logger.Log(logLevel, CreateRow($"{"",-4} {"Trainer",-35} {"Accuracy",9} {"AUC",8} {"AUPRC",8} {"F1-score",9} {"Duration",9} {"#Iteration",10}", Width));
3838
}
3939

4040
internal static void PrintMulticlassClassificationMetricsHeader(LogLevel logLevel)
4141
{
42-
logger.Log(logLevel, CreateRow($"{"",-4} {"Trainer",-35} {"MicroAccuracy",14} {"MacroAccuracy",14} {"Duration",9} {"#Iteration",9}", Width));
42+
logger.Log(logLevel, CreateRow($"{"",-4} {"Trainer",-35} {"MicroAccuracy",14} {"MacroAccuracy",14} {"Duration",9} {"#Iteration",10}", Width));
4343
}
4444

4545
internal static void PrintRegressionMetricsHeader(LogLevel logLevel)
4646
{
47-
logger.Log(logLevel, CreateRow($"{"",-4} {"Trainer",-35} {"RSquared",8} {"LossFn",10} {"Absolute-loss",13} {"Squared-loss",12} {"RMS-loss",10} {"Duration",9} {"#Iteration",9}", Width));
47+
logger.Log(logLevel, CreateRow($"{"",-4} {"Trainer",-35} {"RSquared",8} {"Absolute-loss",13} {"Squared-loss",12} {"RMS-loss",8} {"Duration",9} {"#Iteration",10}", Width));
4848
}
4949

5050
internal static void ExperimentResultsHeader(LogLevel logLevel, string mltask, string datasetName, string labelName, string time, int numModelsExplored)
@@ -58,7 +58,7 @@ internal static void ExperimentResultsHeader(LogLevel logLevel, string mltask, s
5858
logger.Log(logLevel, CreateRow($"{"ML Task",-7}: {mltask,-20}", Width));
5959
logger.Log(logLevel, CreateRow($"{"Dataset",-7}: {datasetName,-25}", Width));
6060
logger.Log(logLevel, CreateRow($"{"Label",-6}: {labelName,-25}", Width));
61-
logger.Log(logLevel, CreateRow($"{"Exploration time",-16}: {time} Secs", Width));
61+
logger.Log(logLevel, CreateRow($"{"Total experiment time",-22}: {time} Secs", Width));
6262
logger.Log(logLevel, CreateRow($"{"Total number of models explored",-30}: {numModelsExplored}", Width));
6363
logger.Log(logLevel, TABLESEPERATOR);
6464
}

0 commit comments

Comments
 (0)