DataOperationsCatalog.LoadFromEnumerable 메서드

정의

오버로드

LoadFromEnumerable<TRow>(IEnumerable<TRow>, SchemaDefinition)

사용자 정의 형식의 항목 열거형을 통해 새로 IDataView 만듭니다. 사용자는 소유권을 data 유지 관리하며 결과 데이터 뷰는 해당 내용 data이 변경되지 않습니다. IDataView 변경할 수 없는 것으로 간주되므로 사용자는 데이터가 한 번만 커서가 지정된다는 것을 알지 못하면 동일한 결과를 반환하는 여러 열거 data 형을 지원해야 합니다.

스트리밍 데이터 뷰에 대한 일반적인 사용 방법 중 하나는 필요에 따라 데이터를 지연 로드하는 데이터 뷰를 만든 다음, 미리 학습된 변환을 적용하고 변환 결과를 위해 이를 통해 커서를 사용하는 것입니다.

LoadFromEnumerable<TRow>(IEnumerable<TRow>, DataViewSchema)

IDataView 제공된 DataViewSchema형식을 사용하여 사용자 정의 형식의 항목 열거 가능 항목을 새로 만듭니다. 이 항목에는 형식이 캡처할 수 있는 것보다 스키마에 대한 자세한 정보가 포함될 수 있습니다.

LoadFromEnumerable<TRow>(IEnumerable<TRow>, SchemaDefinition)

사용자 정의 형식의 항목 열거형을 통해 새로 IDataView 만듭니다. 사용자는 소유권을 data 유지 관리하며 결과 데이터 뷰는 해당 내용 data이 변경되지 않습니다. IDataView 변경할 수 없는 것으로 간주되므로 사용자는 데이터가 한 번만 커서가 지정된다는 것을 알지 못하면 동일한 결과를 반환하는 여러 열거 data 형을 지원해야 합니다.

스트리밍 데이터 뷰에 대한 일반적인 사용 방법 중 하나는 필요에 따라 데이터를 지연 로드하는 데이터 뷰를 만든 다음, 미리 학습된 변환을 적용하고 변환 결과를 위해 이를 통해 커서를 사용하는 것입니다.

public Microsoft.ML.IDataView LoadFromEnumerable<TRow> (System.Collections.Generic.IEnumerable<TRow> data, Microsoft.ML.Data.SchemaDefinition schemaDefinition = default) where TRow : class;
member this.LoadFromEnumerable : seq<'Row (requires 'Row : null)> * Microsoft.ML.Data.SchemaDefinition -> Microsoft.ML.IDataView (requires 'Row : null)
Public Function LoadFromEnumerable(Of TRow As Class) (data As IEnumerable(Of TRow), Optional schemaDefinition As SchemaDefinition = Nothing) As IDataView

형식 매개 변수

TRow

사용자 정의 항목 유형입니다.

매개 변수

data
IEnumerable<TRow>

로 변환할 형식 TRow 을 포함하는 열거 가능한 데이터입니다 IDataView.

schemaDefinition
SchemaDefinition

만들 데이터 뷰의 선택적 스키마 정의입니다. 이면 null스키마 정의가 .에서 TRow유추됩니다.

반환

생성된 IDataView.

예제

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

namespace Samples.Dynamic
{
    public static class LoadFromEnumerable
    {
        // Creating IDataView from IEnumerable, and setting the size of the vector
        // at runtime. When the data model is defined through types, setting the
        // size of the vector is done through the VectorType annotation. When the
        // size of the data is not known at compile time, the Schema can be directly
        // modified at runtime and the size of the vector set there. This is
        // important, because most of the ML.NET trainers require the Features
        // vector to be of known size. 
        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.
            IEnumerable<DataPointVector> enumerableKnownSize = new DataPointVector[]
            {
               new DataPointVector{ Features = new float[]{ 1.2f, 3.4f, 4.5f, 3.2f,
                   7,5f } },

               new DataPointVector{ Features = new float[]{ 4.2f, 3.4f, 14.65f,
                   3.2f, 3,5f } },

               new DataPointVector{ Features = new float[]{ 1.6f, 3.5f, 4.5f, 6.2f,
                   3,5f } },

            };

            // Load dataset into an IDataView. 
            IDataView data = mlContext.Data.LoadFromEnumerable(enumerableKnownSize);
            var featureColumn = data.Schema["Features"].Type as VectorDataViewType;
            // Inspecting the schema
            Console.WriteLine($"Is the size of the Features column known: " +
                $"{featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}");

            // Preview
            //
            // Is the size of the Features column known? True.
            // Size: 5.

            // If the size of the vector is unknown at compile time, it can be set 
            // at runtime.
            IEnumerable<DataPoint> enumerableUnknownSize = new DataPoint[]
            {
               new DataPoint{ Features = new float[]{ 1.2f, 3.4f, 4.5f } },
               new DataPoint{ Features = new float[]{ 4.2f, 3.4f, 1.6f } },
               new DataPoint{ Features = new float[]{ 1.6f, 3.5f, 4.5f } },
            };

            // The feature dimension (typically this will be the Count of the array 
            // of the features vector known at runtime).
            int featureDimension = 3;
            var definedSchema = SchemaDefinition.Create(typeof(DataPoint));
            featureColumn = definedSchema["Features"]
                .ColumnType as VectorDataViewType;

            Console.WriteLine($"Is the size of the Features column known: " +
                $"{featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}");

            // Preview
            //
            // Is the size of the Features column known? False.
            // Size: 0.

            // Set the column type to be a known-size vector.
            var vectorItemType = ((VectorDataViewType)definedSchema[0].ColumnType)
                .ItemType;
            definedSchema[0].ColumnType = new VectorDataViewType(vectorItemType,
                featureDimension);

            // Read the data into an IDataView with the modified schema supplied in
            IDataView data2 = mlContext.Data
                .LoadFromEnumerable(enumerableUnknownSize, definedSchema);

            featureColumn = data2.Schema["Features"].Type as VectorDataViewType;
            // Inspecting the schema
            Console.WriteLine($"Is the size of the Features column known: " +
                $"{featureColumn.IsKnownSize}.\nSize: {featureColumn.Size}");

            // Preview
            //
            // Is the size of the Features column known? True. 
            // Size: 3.
        }
    }

    public class DataPoint
    {
        public float[] Features { get; set; }
    }

    public class DataPointVector
    {
        [VectorType(5)]
        public float[] Features { get; set; }
    }
}

적용 대상

LoadFromEnumerable<TRow>(IEnumerable<TRow>, DataViewSchema)

IDataView 제공된 DataViewSchema형식을 사용하여 사용자 정의 형식의 항목 열거 가능 항목을 새로 만듭니다. 이 항목에는 형식이 캡처할 수 있는 것보다 스키마에 대한 자세한 정보가 포함될 수 있습니다.

public Microsoft.ML.IDataView LoadFromEnumerable<TRow> (System.Collections.Generic.IEnumerable<TRow> data, Microsoft.ML.DataViewSchema schema) where TRow : class;
member this.LoadFromEnumerable : seq<'Row (requires 'Row : null)> * Microsoft.ML.DataViewSchema -> Microsoft.ML.IDataView (requires 'Row : null)
Public Function LoadFromEnumerable(Of TRow As Class) (data As IEnumerable(Of TRow), schema As DataViewSchema) As IDataView

형식 매개 변수

TRow

사용자 정의 항목 유형입니다.

매개 변수

data
IEnumerable<TRow>

로 변환할 형식 TRow 을 포함하는 열거 가능한 데이터입니다 IDataView.

schema
DataViewSchema

반환 IDataView된 스키마입니다.

반환

IDataView 지정된 schema.

설명

사용자는 소유권을 data 유지 관리하며 결과 데이터 뷰는 해당 내용 data이 변경되지 않습니다. IDataView 변경할 수 없는 것으로 간주되므로 사용자는 데이터가 한 번만 커서가 지정된다는 것을 알지 못하면 동일한 결과를 반환하는 여러 열거 data 형을 지원해야 합니다. 스트리밍 데이터 뷰에 대한 일반적인 사용 방법 중 하나는 필요에 따라 데이터를 지연 로드하는 데이터 뷰를 만든 다음, 미리 학습된 변환을 적용하고 변환 결과를 위해 이를 통해 커서를 사용하는 것입니다. 한 가지 실용적인 사용법은 .를 통해 DataViewSchema.Annotations기능 열 이름을 제공하는 것입니다.

적용 대상