Share via


DataOperationsCatalog.ShuffleRows 메서드

정의

의 행 순서를 섞습니다 input.

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

매개 변수

input
IDataView

입력 데이터입니다.

seed
Nullable<Int32>

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

shufflePoolSize
Int32

풀에 저장할 행의 수입니다. 이 값을 1로 설정하면 풀 순서 섞기를 해제하고 ShuffleRows(IDataView, Nullable<Int32>, Int32, Boolean) 임의의 순서로 읽어 순서를 섞 input 는 작업만 수행합니다.

shuffleSource
Boolean

이 경우 false변환은 임의 순서로 읽 input 지 않고 풀링만 사용하여 순서를 섞습니다. 속성이 .인 경우 이 매개 변수는 CanShuffleinputfalse영향을 주지 않습니다.

반환

예제

using System;
using System.Collections.Generic;
using Microsoft.ML;

namespace Samples.Dynamic
{
    public static class ShuffleRows
    {
        // Sample class showing how to shuffle rows in 
        // IDataView.
        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 enumerableOfData = GetSampleTemperatureData(5);
            var data = mlContext.Data.LoadFromEnumerable(enumerableOfData);

            // Before we apply a filter, examine all the records in the dataset.
            Console.WriteLine($"Date\tTemperature");
            foreach (var row in enumerableOfData)
            {
                Console.WriteLine($"{row.Date.ToString("d")}" +
                    $"\t{row.Temperature}");
            }
            Console.WriteLine();
            // Expected output:
            //  Date    Temperature
            //  1/2/2012        36
            //  1/3/2012        36
            //  1/4/2012        34
            //  1/5/2012        35
            //  1/6/2012        35

            // Shuffle the dataset.
            var shuffledData = mlContext.Data.ShuffleRows(data, seed: 123);

            // Look at the shuffled data and observe that the rows are in a
            // randomized order.
            var enumerable = mlContext.Data
                .CreateEnumerable<SampleTemperatureData>(shuffledData,
                reuseRowObject: true);

            Console.WriteLine($"Date\tTemperature");
            foreach (var row in enumerable)
            {
                Console.WriteLine($"{row.Date.ToString("d")}" +
                $"\t{row.Temperature}");
            }
            // Expected output:
            //  Date    Temperature
            //  1/4/2012        34
            //  1/2/2012        36
            //  1/5/2012        35
            //  1/3/2012        36
            //  1/6/2012        35
        }

        private class SampleTemperatureData
        {
            public DateTime Date { get; set; }
            public float Temperature { get; set; }
        }

        /// <summary>
        /// Get a fake temperature dataset.
        /// </summary>
        /// <param name="exampleCount">The number of examples to return.</param>
        /// <returns>An enumerable of <see cref="SampleTemperatureData"/>.</returns>
        private static IEnumerable<SampleTemperatureData> GetSampleTemperatureData(
            int exampleCount)

        {
            var rng = new Random(1234321);
            var date = new DateTime(2012, 1, 1);
            float temperature = 39.0f;

            for (int i = 0; i < exampleCount; i++)
            {
                date = date.AddDays(1);
                temperature += rng.Next(-5, 5);
                yield return new SampleTemperatureData
                {
                    Date = date,
                    Temperature =
                    temperature
                };

            }
        }
    }
}

설명

ShuffleRows(IDataView, Nullable<Int32>, Int32, Boolean) 는 스트리밍 방법을 사용하여 모든 입력 IDataView 의 행을 순서를 섞습니다. 전체 데이터 세트를 메모리에 로드하지 않으려면 행 풀을 사용하여 출력할 행을 임의 shufflePoolSize 로 선택합니다. 풀은 .의 첫 번째 shufflePoolSize 행에서 input생성됩니다. 그런 다음, 행은 풀에서 input 임의로 생성되고 모든 행이 생성될 때까지 다음 행으로 바뀝니다. 그 결과 IDataView 임의의 순서로 input 행과 같은 크기가 새로 생성됩니다. 속성이 CanShuffle true이면 임의 input 순서로 풀로 읽혀 두 개의 임의 소스를 제공합니다.

적용 대상