From e2eee414cdc011f4995d4f7d4cf81f89169cf14a Mon Sep 17 00:00:00 2001 From: AnoojNair Date: Mon, 8 Jun 2020 17:27:56 +1200 Subject: [PATCH 1/2] finds the best run for a given experiment. --- src/MLOps.NET/IMLLifeCycleManager.cs | 11 ++++++++++- src/MLOps.NET/MLLifeCycleManager.cs | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/MLOps.NET/IMLLifeCycleManager.cs b/src/MLOps.NET/IMLLifeCycleManager.cs index 48891127..d0ac84ad 100644 --- a/src/MLOps.NET/IMLLifeCycleManager.cs +++ b/src/MLOps.NET/IMLLifeCycleManager.cs @@ -1,4 +1,5 @@ -using System; +using MLOps.NET.Entities.Entities; +using System; using System.Threading.Tasks; namespace MLOps.NET @@ -53,5 +54,13 @@ public interface IMLLifeCycleManager /// Absolute or relative path to the model /// Task UploadModelAsync(Guid runId, string filePath); + + /// + /// Gets the best run for an experiment based on a metric for e.g "Accuracy" + /// + /// + /// + /// + IRun GetBestRun(Guid experimentId, string metricName); } } diff --git a/src/MLOps.NET/MLLifeCycleManager.cs b/src/MLOps.NET/MLLifeCycleManager.cs index 5b114bed..525ef443 100644 --- a/src/MLOps.NET/MLLifeCycleManager.cs +++ b/src/MLOps.NET/MLLifeCycleManager.cs @@ -1,4 +1,5 @@ -using MLOps.NET.Storage; +using MLOps.NET.Entities.Entities; +using MLOps.NET.Storage; using System; using System.Linq; using System.Threading.Tasks; @@ -71,6 +72,20 @@ public async Task UploadModelAsync(Guid runId, string filePath) await ModelRepository.UploadModelAsync(runId, filePath); } + /// + public IRun GetBestRun(Guid experimentId, string metricName) + { + EnsureStorageProviderConfigured(); + var allRuns = MetaDataStore.GetRuns(experimentId); + // Flattening the metrics for all the runs for a given experiment into one list and finding the best among them. + var bestRunId = allRuns.SelectMany(r => r.Metrics) + .Where(m => m.MetricName.ToLowerInvariant() == metricName.ToLowerInvariant()) + .OrderByDescending(m => m.Value) + .First().RunId; + + return allRuns.FirstOrDefault(r => r.Id == bestRunId); + } + /// private void EnsureStorageProviderConfigured() { From e4826227a2f4e770f14baa0926e9c9614e9d6128 Mon Sep 17 00:00:00 2001 From: AnoojNair Date: Tue, 9 Jun 2020 05:38:24 +1200 Subject: [PATCH 2/2] removing a comment. --- src/MLOps.NET/MLLifeCycleManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MLOps.NET/MLLifeCycleManager.cs b/src/MLOps.NET/MLLifeCycleManager.cs index 525ef443..be930756 100644 --- a/src/MLOps.NET/MLLifeCycleManager.cs +++ b/src/MLOps.NET/MLLifeCycleManager.cs @@ -77,7 +77,6 @@ public IRun GetBestRun(Guid experimentId, string metricName) { EnsureStorageProviderConfigured(); var allRuns = MetaDataStore.GetRuns(experimentId); - // Flattening the metrics for all the runs for a given experiment into one list and finding the best among them. var bestRunId = allRuns.SelectMany(r => r.Metrics) .Where(m => m.MetricName.ToLowerInvariant() == metricName.ToLowerInvariant()) .OrderByDescending(m => m.Value)