Aracılığıyla paylaş


AutoMLExperiment Sınıf

Tanım

AutoML denemesi sınıfı

public class AutoMLExperiment
type AutoMLExperiment = class
Public Class AutoMLExperiment
Devralma
AutoMLExperiment

Örnekler

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());
        }
    }
}

Oluşturucular

AutoMLExperiment(MLContext, AutoMLExperiment+AutoMLExperimentSettings)

AutoML denemesi sınıfı

Yöntemler

AddSearchSpace(String, SearchSpace)

AutoML denemesi sınıfı

Run()

Denemeyi çalıştırın ve en iyi deneme sonucunu eşitlenmiş olarak döndürin.

RunAsync(CancellationToken)

Denemeyi çalıştırın ve zaman uyumsuz olarak en iyi deneme sonucunu döndürin. Deneme iptal edildiğinde tamamlanan bir deneme varsa geçerli en iyi deneme sonucunu döndürür ve deneme tamamlanmadığında ct "Deneme çalıştırması tamamlanmadan eğitim süresi tamamlandı" iletisiyle birlikte oluşturur TimeoutException . Dikkat edilmesi gereken bir diğer şey de bu işlevin iptal edildikten hemen sonra ct döndürülmeyeceğidir. Bunun yerine, tüm eğitim sürecini iptal etmek ve çalışan tüm denemelerin iptal olmasını veya tamamlanmasını beklemek için çağrısında Microsoft.ML.MLContext.CancelExecution bulunur.

SetMaximumMemoryUsageInMegaByte(Double)

AutoML denemesi sınıfı

SetMaxModelToExplore(Int32)

AutoML denemesi sınıfı

SetMonitor<TMonitor>()

AutoML denemesi sınıfı

SetMonitor<TMonitor>(Func<IServiceProvider,TMonitor>)

AutoML denemesi sınıfı

SetMonitor<TMonitor>(TMonitor)

AutoML denemesi sınıfı

SetTrainingTimeInSeconds(UInt32)

AutoML denemesi sınıfı

SetTrialRunner<TTrialRunner>()

AutoML denemesi sınıfı

SetTrialRunner<TTrialRunner>(Func<IServiceProvider,TTrialRunner>)

AutoML denemesi sınıfı

SetTrialRunner<TTrialRunner>(TTrialRunner)

AutoML denemesi sınıfı

SetTuner<TTuner>()

AutoML denemesi sınıfı

SetTuner<TTuner>(Func<IServiceProvider,TTuner>)

AutoML denemesi sınıfı

SetTuner<TTuner>(TTuner)

AutoML denemesi sınıfı

Uzantı Metotları

SetBinaryClassificationMetric(AutoMLExperiment, BinaryClassificationMetric, String, String)

için AutoMLExperimentdeğerlendirme yöneticisi olarak ayarlayınMicrosoft.ML.AutoML.BinaryMetricManager. Bu, değerlendirme ölçümü olarak kullanımlar metric yaparAutoMLExperiment.

SetCheckpoint(AutoMLExperiment, String)

için AutoMLExperimentdenetim noktası klasörünü ayarlayın. Denetim noktası klasörü geçici çıkışı kaydetmek, çalıştırma geçmişini ve diğer birçok şeyi kaydetmek için kullanılır. Bu klasör, son denetim noktasından eğitim sürecini geri yüklemek ve eğitime devam etmek için kullanılacaktır.

SetCostFrugalTuner(AutoMLExperiment)

Hiper parametre iyileştirmesi için ayarlayıcı olarak ayarlayın Microsoft.ML.AutoML.CostFrugalTuner .

SetDataset(AutoMLExperiment, DataOperationsCatalog+TrainTestData)

için AutoMLExperimenteğitim ve doğrulama veri kümesini ayarlayın. Bu, AutoMLExperiment bir modeli eğitmek için 'den trainValidationSplit ve TrainSet modeli değerlendirmek için 'den trainValidationSplit kullanırTestSet.

SetDataset(AutoMLExperiment, IDataView, IDataView, Boolean)

için AutoMLExperimenteğitim ve doğrulama veri kümesini ayarlayın. Bu, AutoMLExperiment modeli eğitmek için kullanır train ve modeli değerlendirmek için kullanır validation .

SetDataset(AutoMLExperiment, IDataView, Int32, String)

için AutoMLExperimentçapraz doğrulama veri kümesini ayarlayın. Bu, modeli eğitmek ve değerlendirmek için n=fold çapraz doğrulamayı bölmeyi dataset kullanırAutoMLExperiment.

SetEciCostFrugalTuner(AutoMLExperiment)

hiper parametre iyileştirmesi için ayarlayıcı olarak ayarlayın Microsoft.ML.AutoML.EciCostFrugalTuner . Bu tarayıcı yalnızca içinden arama SweepablePipelinealanıyla çalışır.

SetGridSearchTuner(AutoMLExperiment, Int32)

hiper parametre iyileştirmesi için ayarlayıcı olarak ayarlayın Microsoft.ML.AutoML.GridSearchTuner .

SetMulticlassClassificationMetric(AutoMLExperiment, MulticlassClassificationMetric, String, String)

için AutoMLExperimentdeğerlendirme yöneticisi olarak ayarlayınMicrosoft.ML.AutoML.MultiClassMetricManager. Bu, değerlendirme ölçümü olarak kullanımlar metric yaparAutoMLExperiment.

SetPerformanceMonitor(AutoMLExperiment, Int32)

için AutoMLExperimentolarak IPerformanceMonitor ayarlayınDefaultPerformanceMonitor.

SetPerformanceMonitor<TPerformanceMonitor>(AutoMLExperiment)

için AutoMLExperimentolarak IPerformanceMonitor özel bir performans izleyicisi ayarlayın.

SetPerformanceMonitor<TPerformanceMonitor>(AutoMLExperiment, Func<IServiceProvider,TPerformanceMonitor>)

için AutoMLExperimentolarak IPerformanceMonitor özel bir performans izleyicisi ayarlayın.

SetPipeline(AutoMLExperiment, SweepablePipeline)

Eğitim için ayarlayın pipeline . Bu, automl traininng için de AutoMLExperiment ve Microsoft.ML.AutoML.MLContextMonitorMicrosoft.ML.AutoML.EciCostFrugalTuner kullanır Microsoft.ML.AutoML.SweepablePipelineRunner .

SetRandomSearchTuner(AutoMLExperiment, Nullable<Int32>)

hiper parametre iyileştirmesi için ayarlayıcı olarak ayarlayın Microsoft.ML.AutoML.RandomSearchTuner . sağlanırsa seed , başlatmak Microsoft.ML.AutoML.RandomSearchTuneriçin bu tohumu kullanır. Seed Aksi takdirde kullanılır.

SetRegressionMetric(AutoMLExperiment, RegressionMetric, String, String)

için AutoMLExperimentdeğerlendirme yöneticisi olarak ayarlayınMicrosoft.ML.AutoML.RegressionMetricManager. Bu, değerlendirme ölçümü olarak kullanımlar metric yaparAutoMLExperiment.

SetSmacTuner(AutoMLExperiment, Int32, Int32, Int32, Int32, Single, Int32, Int32, Double, Int32)

Hiper parametre iyileştirmesi için ayarlayıcı olarak ayarlayın Microsoft.ML.AutoML.SmacTuner . smac'in performansı, nMinForSpit smac'in iç regresörüne uydurmak için kullanılan ve splitRatiotarafından numberOfTreesbelirlenen büyük bir genişletmededir.

Şunlara uygulanır