AutoMLExperiment 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
AutoML 실험에 대한 클래스
public class AutoMLExperiment
type AutoMLExperiment = class
Public Class AutoMLExperiment
- 상속
-
AutoMLExperiment
예제
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ML.Data;
namespace Microsoft.ML.AutoML.Samples
{
public static class AutoMLExperiment
{
public static async Task RunAsync()
{
var seed = 0;
// Create a new context for ML.NET operations. It can be used for
// exception tracking and logging, as a catalog of available operations
// and as the source of randomness. Setting the seed to a fixed number
// in this example to make outputs deterministic.
var context = new MLContext(seed);
// Create a list of training data points and convert it to IDataView.
var data = GenerateRandomBinaryClassificationDataPoints(100, seed);
var dataView = context.Data.LoadFromEnumerable(data);
var trainTestSplit = context.Data.TrainTestSplit(dataView);
// Define the sweepable pipeline using predefined binary trainers and search space.
var pipeline = context.Auto().BinaryClassification(labelColumnName: "Label", featureColumnName: "Features");
// Create an AutoML experiment
var experiment = context.Auto().CreateExperiment();
// Redirect AutoML log to console
context.Log += (object o, LoggingEventArgs e) =>
{
if (e.Source == nameof(AutoMLExperiment) && e.Kind > Runtime.ChannelMessageKind.Trace)
{
Console.WriteLine(e.RawMessage);
}
};
// Config experiment to optimize "Accuracy" metric on given dataset.
// This experiment will run hyper-parameter optimization on given pipeline
experiment.SetPipeline(pipeline)
.SetDataset(trainTestSplit.TrainSet, fold: 5) // use 5-fold cross validation to evaluate each trial
.SetBinaryClassificationMetric(BinaryClassificationMetric.Accuracy, "Label")
.SetMaxModelToExplore(100); // explore 100 trials
// start automl experiment
var result = await experiment.RunAsync();
// Expected output samples during training:
// Update Running Trial - Id: 0
// Update Completed Trial - Id: 0 - Metric: 0.5536912515402218 - Pipeline: FastTreeBinary - Duration: 595 - Peak CPU: 0.00 % -Peak Memory in MB: 35.81
// Update Best Trial - Id: 0 - Metric: 0.5536912515402218 - Pipeline: FastTreeBinary
// evaluate test dataset on best model.
var bestModel = result.Model;
var eval = bestModel.Transform(trainTestSplit.TestSet);
var metrics = context.BinaryClassification.Evaluate(eval);
PrintMetrics(metrics);
// Expected output:
// Accuracy: 0.67
// AUC: 0.75
// F1 Score: 0.33
// Negative Precision: 0.88
// Negative Recall: 0.70
// Positive Precision: 0.25
// Positive Recall: 0.50
// TEST POSITIVE RATIO: 0.1667(2.0 / (2.0 + 10.0))
// Confusion table
// ||======================
// PREDICTED || positive | negative | Recall
// TRUTH ||======================
// positive || 1 | 1 | 0.5000
// negative || 3 | 7 | 0.7000
// ||======================
// Precision || 0.2500 | 0.8750 |
}
private static IEnumerable<BinaryClassificationDataPoint> GenerateRandomBinaryClassificationDataPoints(int count,
int seed = 0)
{
var random = new Random(seed);
float randomFloat() => (float)random.NextDouble();
for (int i = 0; i < count; i++)
{
var label = randomFloat() > 0.5f;
yield return new BinaryClassificationDataPoint
{
Label = label,
// Create random features that are correlated with the label.
// For data points with false label, the feature values are
// slightly increased by adding a constant.
Features = Enumerable.Repeat(label, 50)
.Select(x => x ? randomFloat() : randomFloat() +
0.1f).ToArray()
};
}
}
// Example with label and 50 feature values. A data set is a collection of
// such examples.
private class BinaryClassificationDataPoint
{
public bool Label { get; set; }
[VectorType(50)]
public float[] Features { get; set; }
}
// Class used to capture predictions.
private class Prediction
{
// Original label.
public bool Label { get; set; }
// Predicted label from the trainer.
public bool PredictedLabel { get; set; }
}
// Pretty-print BinaryClassificationMetrics objects.
private static void PrintMetrics(BinaryClassificationMetrics metrics)
{
Console.WriteLine($"Accuracy: {metrics.Accuracy:F2}");
Console.WriteLine($"AUC: {metrics.AreaUnderRocCurve:F2}");
Console.WriteLine($"F1 Score: {metrics.F1Score:F2}");
Console.WriteLine($"Negative Precision: " +
$"{metrics.NegativePrecision:F2}");
Console.WriteLine($"Negative Recall: {metrics.NegativeRecall:F2}");
Console.WriteLine($"Positive Precision: " +
$"{metrics.PositivePrecision:F2}");
Console.WriteLine($"Positive Recall: {metrics.PositiveRecall:F2}\n");
Console.WriteLine(metrics.ConfusionMatrix.GetFormattedConfusionTable());
}
}
}
생성자
AutoMLExperiment(MLContext, AutoMLExperiment+AutoMLExperimentSettings) |
AutoML 실험에 대한 클래스 |
메서드
AddSearchSpace(String, SearchSpace) |
AutoML 실험에 대한 클래스 |
Run() |
실험을 실행하고 동기화하여 최상의 평가판 결과를 반환합니다. |
RunAsync(CancellationToken) |
실험을 실행하고 최상의 평가판 결과를 비동기적으로 반환합니다. 이 실험은 취소될 때 |
SetMaximumMemoryUsageInMegaByte(Double) |
AutoML 실험에 대한 클래스 |
SetMaxModelToExplore(Int32) |
AutoML 실험에 대한 클래스 |
SetMonitor<TMonitor>() |
AutoML 실험에 대한 클래스 |
SetMonitor<TMonitor>(Func<IServiceProvider,TMonitor>) |
AutoML 실험에 대한 클래스 |
SetMonitor<TMonitor>(TMonitor) |
AutoML 실험에 대한 클래스 |
SetTrainingTimeInSeconds(UInt32) |
AutoML 실험에 대한 클래스 |
SetTrialRunner<TTrialRunner>() |
AutoML 실험에 대한 클래스 |
SetTrialRunner<TTrialRunner>(Func<IServiceProvider,TTrialRunner>) |
AutoML 실험에 대한 클래스 |
SetTrialRunner<TTrialRunner>(TTrialRunner) |
AutoML 실험에 대한 클래스 |
SetTuner<TTuner>() |
AutoML 실험에 대한 클래스 |
SetTuner<TTuner>(Func<IServiceProvider,TTuner>) |
AutoML 실험에 대한 클래스 |
SetTuner<TTuner>(TTuner) |
AutoML 실험에 대한 클래스 |
확장 메서드
SetBinaryClassificationMetric(AutoMLExperiment, BinaryClassificationMetric, String, String) |
에 대한 AutoMLExperiment평가 관리자로 설정합니다Microsoft.ML.AutoML.BinaryMetricManager. 이렇게 하면 AutoMLExperiment 를 평가 메트릭으로 사용합니다 |
SetCheckpoint(AutoMLExperiment, String) |
에 대한 검사점 폴더를 AutoMLExperiment설정합니다. 검사점 폴더는 임시 출력, 실행 기록 및 마지막 검사점에서 학습 프로세스를 복원하고 학습을 계속하는 데 사용할 다른 많은 항목을 저장하는 데 사용됩니다. |
SetCostFrugalTuner(AutoMLExperiment) |
하이퍼 매개 변수 최적화를 위한 튜너로 설정합니다 Microsoft.ML.AutoML.CostFrugalTuner . |
SetDataset(AutoMLExperiment, DataOperationsCatalog+TrainTestData) |
에 대한 AutoMLExperiment학습 및 유효성 검사 데이터 세트를 설정합니다. 이렇게 하면 AutoMLExperiment 에서 을 사용하여 TrainSet 모델을 학습시키고 에서 |
SetDataset(AutoMLExperiment, IDataView, IDataView, Boolean) |
에 대한 AutoMLExperiment학습 및 유효성 검사 데이터 세트를 설정합니다. 이렇게 하면 AutoMLExperiment 을 사용하여 |
SetDataset(AutoMLExperiment, IDataView, Int32, String) |
에 대한 AutoMLExperiment교차 유효성 검사 데이터 세트를 설정합니다. 이렇게 하면 AutoMLExperiment n= |
SetEciCostFrugalTuner(AutoMLExperiment) |
하이퍼 매개 변수 최적화를 위한 튜너로 설정합니다 Microsoft.ML.AutoML.EciCostFrugalTuner . 이 튜너에서는 의 SweepablePipeline검색 공간에서만 작동합니다. |
SetGridSearchTuner(AutoMLExperiment, Int32) |
하이퍼 매개 변수 최적화를 위한 튜너로 설정합니다 Microsoft.ML.AutoML.GridSearchTuner . |
SetMulticlassClassificationMetric(AutoMLExperiment, MulticlassClassificationMetric, String, String) |
에 대한 AutoMLExperiment평가 관리자로 설정합니다Microsoft.ML.AutoML.MultiClassMetricManager. 이렇게 하면 AutoMLExperiment 를 평가 메트릭으로 사용합니다 |
SetPerformanceMonitor(AutoMLExperiment, Int32) |
을 로 IPerformanceMonitorAutoMLExperiment설정합니다DefaultPerformanceMonitor. |
SetPerformanceMonitor<TPerformanceMonitor>(AutoMLExperiment, Func<IServiceProvider,TPerformanceMonitor>) |
에 대해 사용자 지정 성능 모니터를 AutoMLExperiment로 IPerformanceMonitor 설정합니다. |
SetPerformanceMonitor<TPerformanceMonitor>(AutoMLExperiment) |
에 대해 사용자 지정 성능 모니터를 AutoMLExperiment로 IPerformanceMonitor 설정합니다. |
SetPipeline(AutoMLExperiment, SweepablePipeline) |
학습을 위해 설정합니다 |
SetRandomSearchTuner(AutoMLExperiment, Nullable<Int32>) |
하이퍼 매개 변수 최적화를 위한 튜너로 설정합니다 Microsoft.ML.AutoML.RandomSearchTuner . 가 제공되면 |
SetRegressionMetric(AutoMLExperiment, RegressionMetric, String, String) |
에 대한 AutoMLExperiment평가 관리자로 설정합니다Microsoft.ML.AutoML.RegressionMetricManager. 이렇게 하면 AutoMLExperiment 를 평가 메트릭으로 사용합니다 |
SetSmacTuner(AutoMLExperiment, Int32, Int32, Int32, Int32, Single, Int32, Int32, Double, Int32) |
하이퍼 매개 변수 최적화를 위한 튜너로 설정합니다 Microsoft.ML.AutoML.SmacTuner . smac의 성능은 smac의 내부 회귀기에 맞게 사용되는 , |