DataOperationsCatalog.BootstrapSample 메서드

정의

대략적인 부트스트랩 샘플을 사용합니다 input.

public Microsoft.ML.IDataView BootstrapSample (Microsoft.ML.IDataView input, int? seed = default, bool complement = false);
member this.BootstrapSample : Microsoft.ML.IDataView * Nullable<int> * bool -> Microsoft.ML.IDataView
Public Function BootstrapSample (input As IDataView, Optional seed As Nullable(Of Integer) = Nothing, Optional complement As Boolean = false) As IDataView

매개 변수

input
IDataView

입력 데이터입니다.

seed
Nullable<Int32>

임의 시드입니다. 지정하지 않으면 임의 상태가 대신 .에서 MLContext파생됩니다.

complement
Boolean

이 샘플이 아웃 오브 백 샘플인지 여부, 즉 변환에 의해 선택되지 않은 모든 행입니다. 동일한 시드를 사용하여 보완 샘플 쌍을 만드는 데 사용할 수 있습니다.

반환

예제

using System;
using Microsoft.ML;

namespace Samples.Dynamic
{
    public static class BootstrapSample
    {
        public static void Example()
        {
            // 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.
            var mlContext = new MLContext();

            // Get a small dataset as an IEnumerable.
            var rawData = new[] {
                new DataPoint() { Label = true, Feature = 1.017325f},
                new DataPoint() { Label = false, Feature = 0.6326591f},
                new DataPoint() { Label = false, Feature = 0.0326252f},
                new DataPoint() { Label = false, Feature = 0.8426974f},
                new DataPoint() { Label = true, Feature = 0.9947656f},
                new DataPoint() { Label = true, Feature = 1.017325f},
            };

            var data = mlContext.Data.LoadFromEnumerable(rawData);

            // Now take a bootstrap sample of this dataset to create a new dataset. 
            // The bootstrap is a resampling technique that creates a training set
            // of the same size by picking with replacement from the original
            // dataset. With the bootstrap, we expect that the resampled dataset
            // will have about 63% of the rows of the original dataset
            // (i.e. 1-e^-1), with some rows represented more than once.
            // BootstrapSample is a streaming implementation of the boostrap that
            // enables sampling from a dataset too large to hold in memory. To
            // enable streaming, BootstrapSample approximates the bootstrap by 
            // sampling each row according to a Poisson(1) distribution. Note that
            // this streaming approximation treats each row independently, thus the
            // resampled dataset is not guaranteed to be the same length as the 
            // input dataset. Let's take a look at the behavior of the
            // BootstrapSample by examining a few draws:
            for (int i = 0; i < 3; i++)
            {
                var resample = mlContext.Data.BootstrapSample(data, seed: i);

                var enumerable = mlContext.Data
                    .CreateEnumerable<DataPoint>(resample, reuseRowObject: false);

                Console.WriteLine($"Label\tFeature");
                foreach (var row in enumerable)
                {
                    Console.WriteLine($"{row.Label}\t{row.Feature}");
                }
                Console.WriteLine();
            }
            // Expected output:
            //  Label Feature
            //  True    1.017325
            //  False   0.6326591
            //  False   0.6326591
            //  False   0.6326591
            //  False   0.0326252
            //  False   0.0326252
            //  True    0.8426974
            //  True    0.8426974

            //  Label Feature
            //  True    1.017325
            //  True    1.017325
            //  False   0.6326591
            //  False   0.6326591
            //  False   0.0326252
            //  False   0.0326252
            //  False   0.0326252
            //  True    0.9947656

            //  Label Feature
            //  False   0.6326591
            //  False   0.0326252
            //  True    0.8426974
            //  True    0.8426974
            //  True    0.8426974
        }

        private class DataPoint
        {
            public bool Label { get; set; }

            public float Feature { get; set; }
        }
    }
}

설명

이 샘플러가 부트스트랩 리샘플링의 스트리밍 버전입니다. 전체 데이터 세트를 메모리로 가져와서 다시 샘플링하는 대신 데이터 BootstrapSample(IDataView, Nullable<Int32>, Boolean) 세트를 스트림하고 Poisson(1) 분포를 사용하여 지정된 행이 샘플에 추가되는 횟수를 선택합니다. 매개 complement 변수를 사용하면 동일한 seed을 사용하여 부트스탭 샘플 및 보완적인 아웃 오브 백 샘플을 만들 수 있습니다.

적용 대상