forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make optimizing metric customizable and add trainer whitelist functio…
…nality (dotnet#172)
- Loading branch information
Showing
17 changed files
with
414 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Microsoft.ML.Auto/AutoFitter/DataScorer/BinaryDataScorer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Auto | ||
{ | ||
internal class BinaryDataScorer : IDataScorer<BinaryClassificationMetrics> | ||
{ | ||
private readonly BinaryClassificationMetric _metric; | ||
|
||
public BinaryDataScorer(BinaryClassificationMetric metric) | ||
{ | ||
this._metric = metric; | ||
} | ||
|
||
public double GetScore(BinaryClassificationMetrics metrics) | ||
{ | ||
switch(_metric) | ||
{ | ||
case BinaryClassificationMetric.Accuracy: | ||
return metrics.Accuracy; | ||
case BinaryClassificationMetric.Auc: | ||
return metrics.Auc; | ||
case BinaryClassificationMetric.Auprc: | ||
return metrics.Auprc; | ||
case BinaryClassificationMetric.F1Score: | ||
return metrics.F1Score; | ||
case BinaryClassificationMetric.NegativePrecision: | ||
return metrics.NegativePrecision; | ||
case BinaryClassificationMetric.NegativeRecall: | ||
return metrics.NegativeRecall; | ||
case BinaryClassificationMetric.PositivePrecision: | ||
return metrics.PositivePrecision; | ||
case BinaryClassificationMetric.PositiveRecall: | ||
return metrics.PositiveRecall; | ||
} | ||
|
||
// never expected to reach here | ||
throw new NotSupportedException($"{_metric} is not a supported sweep metric"); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Microsoft.ML.Auto/AutoFitter/DataScorer/IDataScorer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Microsoft.ML.Auto | ||
{ | ||
internal interface IDataScorer<T> | ||
{ | ||
double GetScore(T metrics); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Microsoft.ML.Auto/AutoFitter/DataScorer/MultiDataScorer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Auto | ||
{ | ||
internal class MultiDataScorer : IDataScorer<MultiClassClassifierMetrics> | ||
{ | ||
private readonly MulticlassClassificationMetric _metric; | ||
|
||
public MultiDataScorer(MulticlassClassificationMetric metric) | ||
{ | ||
this._metric = metric; | ||
} | ||
|
||
public double GetScore(MultiClassClassifierMetrics metrics) | ||
{ | ||
switch (_metric) | ||
{ | ||
case MulticlassClassificationMetric.AccuracyMacro: | ||
return metrics.AccuracyMacro; | ||
case MulticlassClassificationMetric.AccuracyMicro: | ||
return metrics.AccuracyMicro; | ||
case MulticlassClassificationMetric.LogLoss: | ||
return metrics.LogLoss; | ||
case MulticlassClassificationMetric.LogLossReduction: | ||
return metrics.LogLossReduction; | ||
case MulticlassClassificationMetric.TopKAccuracy: | ||
return metrics.TopKAccuracy; | ||
} | ||
|
||
// never expected to reach here | ||
throw new NotSupportedException($"{_metric} is not a supported sweep metric"); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Microsoft.ML.Auto/AutoFitter/DataScorer/RegressionDataScorer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Auto | ||
{ | ||
internal class RegressionDataScorer : IDataScorer<RegressionMetrics> | ||
{ | ||
private readonly RegressionMetric _metric; | ||
|
||
public RegressionDataScorer(RegressionMetric metric) | ||
{ | ||
this._metric = metric; | ||
} | ||
|
||
public double GetScore(RegressionMetrics metrics) | ||
{ | ||
switch(_metric) | ||
{ | ||
case RegressionMetric.L1: | ||
return metrics.L1; | ||
case RegressionMetric.L2: | ||
return metrics.L2; | ||
case RegressionMetric.Rms: | ||
return metrics.Rms; | ||
case RegressionMetric.RSquared: | ||
return metrics.RSquared; | ||
} | ||
|
||
// never expected to reach here | ||
throw new NotSupportedException($"{_metric} is not a supported sweep metric"); | ||
} | ||
} | ||
} |
Oops, something went wrong.