TransformExtensionsCatalog.CopyColumns 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
ColumnCopyingEstimator에 지정된 inputColumnName
열의 데이터를 새 열로 복사하는 outputColumnName
를 만듭니다.
public static Microsoft.ML.Transforms.ColumnCopyingEstimator CopyColumns (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName);
static member CopyColumns : Microsoft.ML.TransformsCatalog * string * string -> Microsoft.ML.Transforms.ColumnCopyingEstimator
<Extension()>
Public Function CopyColumns (catalog As TransformsCatalog, outputColumnName As String, inputColumnName As String) As ColumnCopyingEstimator
매개 변수
- catalog
- TransformsCatalog
변환의 카탈로그입니다.
- outputColumnName
- String
의 변환에서 생성된 열의 inputColumnName
이름입니다.
이 열의 데이터 형식은 입력 열의 데이터 형식과 동일합니다.
- inputColumnName
- String
데이터를 복사할 열의 이름입니다. 이 추정기는 모든 데이터 형식에 대해 작동합니다.
반환
예제
using System;
using System.Collections.Generic;
using Microsoft.ML;
namespace Samples.Dynamic
{
public static class CopyColumns
{
public static void Example()
{
// Create a new ML context, for ML.NET operations. It can be used for
// exception tracking and logging, as well as the source of randomness.
var mlContext = new MLContext();
// Create a small dataset as an IEnumerable.
var samples = new List<InputData>()
{
new InputData(){ ImageId = 1, Features = new [] { 1.0f, 1.0f,
1.0f } },
new InputData(){ ImageId = 2, Features = new [] { 2.0f, 2.0f,
2.0f } },
new InputData(){ ImageId = 3, Features = new [] { 3.0f, 3.0f,
3.0f } },
new InputData(){ ImageId = 4, Features = new [] { 4.0f, 4.0f,
4.0f } },
new InputData(){ ImageId = 5, Features = new [] { 5.0f, 5.0f,
5.0f } },
new InputData(){ ImageId = 6, Features = new [] { 6.0f, 6.0f,
6.0f } },
};
// Convert training data to IDataView.
var dataview = mlContext.Data.LoadFromEnumerable(samples);
// CopyColumns is commonly used to rename columns.
// For example, if you want to train towards ImageId, and your trainer
// expects a "Label" column, you can use CopyColumns to rename ImageId
// to Label. Technically, the ImageId column still exists, but it won't
// be materialized unless you actually need it somewhere (e.g. if you
// were to save the transformed data without explicitly dropping the
// column). This is a general property of IDataView's lazy evaluation.
var pipeline = mlContext.Transforms.CopyColumns("Label", "ImageId");
// Now we can transform the data and look at the output to confirm the
// behavior of CopyColumns. Don't forget that this operation doesn't
// actually evaluate data until we read the data below.
var transformedData = pipeline.Fit(dataview).Transform(dataview);
// We can extract the newly created column as an IEnumerable of
// SampleInfertDataTransformed, the class we define below.
var rowEnumerable = mlContext.Data.CreateEnumerable<TransformedData>(
transformedData, reuseRowObject: false);
// And finally, we can write out the rows of the dataset, looking at the
// columns of interest.
Console.WriteLine($"Label and ImageId columns obtained " +
$"post-transformation.");
foreach (var row in rowEnumerable)
Console.WriteLine($"Label: {row.Label} ImageId: {row.ImageId}");
// Expected output:
// ImageId and Label columns obtained post-transformation.
// Label: 1 ImageId: 1
// Label: 2 ImageId: 2
// Label: 3 ImageId: 3
// Label: 4 ImageId: 4
// Label: 5 ImageId: 5
// Label: 6 ImageId: 6
}
private class InputData
{
public int ImageId { get; set; }
public float[] Features { get; set; }
}
private class TransformedData : InputData
{
public int Label { get; set; }
}
}
}