ConversionsExtensionsCatalog.ConvertType Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Aşırı Yüklemeler
ConvertType(TransformsCatalog+ConversionTransforms, InputOutputColumnPair[], DataKind) |
Veri türünü içinde |
ConvertType(TransformsCatalog+ConversionTransforms, String, String, DataKind) |
Veri türünü içinde |
ConvertType(TransformsCatalog+ConversionTransforms, InputOutputColumnPair[], DataKind)
Veri türünü içinde outputKind
belirtilen türe dönüştüren bir TypeConvertingEstimatoroluşturun.
public static Microsoft.ML.Transforms.TypeConvertingEstimator ConvertType (this Microsoft.ML.TransformsCatalog.ConversionTransforms catalog, Microsoft.ML.InputOutputColumnPair[] columns, Microsoft.ML.Data.DataKind outputKind = Microsoft.ML.Data.DataKind.Single);
static member ConvertType : Microsoft.ML.TransformsCatalog.ConversionTransforms * Microsoft.ML.InputOutputColumnPair[] * Microsoft.ML.Data.DataKind -> Microsoft.ML.Transforms.TypeConvertingEstimator
<Extension()>
Public Function ConvertType (catalog As TransformsCatalog.ConversionTransforms, columns As InputOutputColumnPair(), Optional outputKind As DataKind = Microsoft.ML.Data.DataKind.Single) As TypeConvertingEstimator
Parametreler
Dönüştürme dönüşüm kataloğu.
- columns
- InputOutputColumnPair[]
Giriş ve çıkış sütunları. Bu dönüşüm sayısal, boole, metin DateTime ve anahtar veri türleri üzerinde çalışır.
- outputKind
- DataKind
Beklenen çıkış sütunu türü.
Döndürülenler
Örnekler
using System;
using Microsoft.ML;
using Microsoft.ML.Data;
namespace Samples.Dynamic
{
// This example illustrates how to convert multiple columns of different types
// to one type, in this case System.Single.
// This is often a useful data transformation before concatenating the features
// together and passing them to a particular estimator.
public static class ConvertTypeMultiColumn
{
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(seed: 1);
var rawData = new[] {
new InputData() { Feature1 = true, Feature2 = "0.4",
Feature3 = DateTime.Now, Feature4 = 0.145},
new InputData() { Feature1 = false, Feature2 = "0.5",
Feature3 = DateTime.Today, Feature4 = 3.14},
new InputData() { Feature1 = false, Feature2 = "14",
Feature3 = DateTime.Today, Feature4 = 0.2046},
new InputData() { Feature1 = false, Feature2 = "23",
Feature3 = DateTime.Now, Feature4 = 0.1206},
new InputData() { Feature1 = true, Feature2 = "8904",
Feature3 = DateTime.UtcNow, Feature4 = 8.09},
};
// Convert the data to an IDataView.
var data = mlContext.Data.LoadFromEnumerable(rawData);
// Construct the pipeline.
var pipeline = mlContext.Transforms.Conversion.ConvertType(new[]
{
new InputOutputColumnPair("Converted1", "Feature1"),
new InputOutputColumnPair("Converted2", "Feature2"),
new InputOutputColumnPair("Converted3", "Feature3"),
new InputOutputColumnPair("Converted4", "Feature4"),
},
DataKind.Single);
// Let's fit our pipeline to the data.
var transformer = pipeline.Fit(data);
// Transforming the same data. This will add the 4 columns defined in
// the pipeline, containing the converted
// values of the initial columns.
var transformedData = transformer.Transform(data);
// Shape the transformed data as a strongly typed IEnumerable.
var convertedData = mlContext.Data.CreateEnumerable<TransformedData>(
transformedData, true);
// Printing the results.
Console.WriteLine("Converted1\t Converted2\t Converted3\t Converted4");
foreach (var item in convertedData)
Console.WriteLine($"\t{item.Converted1}\t {item.Converted2}\t\t " +
$"{item.Converted3}\t {item.Converted4}");
// Transformed data.
//
// Converted1 Converted2 Converted3 Converted4
// 1 0.4 6.368921E+17 0.145
// 0 0.5 6.368916E+17 3.14
// 0 14 6.368916E+17 0.2046
// 0 23 6.368921E+17 0.1206
// 1 8904 6.368924E+17 8.09
}
// The initial data type
private class InputData
{
public bool Feature1;
public string Feature2;
public DateTime Feature3;
public double Feature4;
}
// The resulting data type after the transformation
private class TransformedData : InputData
{
public float Converted1 { get; set; }
public float Converted2 { get; set; }
public float Converted3 { get; set; }
public float Converted4 { get; set; }
}
}
}
Açıklamalar
Bu dönüşüm birkaç sütun üzerinde çalışabilir.
Şunlara uygulanır
ConvertType(TransformsCatalog+ConversionTransforms, String, String, DataKind)
Veri türünü içinde outputKind
belirtilen türe dönüştüren bir TypeConvertingEstimatoroluşturun.
public static Microsoft.ML.Transforms.TypeConvertingEstimator ConvertType (this Microsoft.ML.TransformsCatalog.ConversionTransforms catalog, string outputColumnName, string inputColumnName = default, Microsoft.ML.Data.DataKind outputKind = Microsoft.ML.Data.DataKind.Single);
static member ConvertType : Microsoft.ML.TransformsCatalog.ConversionTransforms * string * string * Microsoft.ML.Data.DataKind -> Microsoft.ML.Transforms.TypeConvertingEstimator
<Extension()>
Public Function ConvertType (catalog As TransformsCatalog.ConversionTransforms, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional outputKind As DataKind = Microsoft.ML.Data.DataKind.Single) As TypeConvertingEstimator
Parametreler
Dönüştürme dönüşüm kataloğu.
- outputColumnName
- String
dönüştürmesinden kaynaklanan sütunun inputColumnName
adı.
- inputColumnName
- String
Dönüştürülecek sütunun adı. olarak ayarlanırsa null
outputColumnName
değeri kaynak olarak kullanılır.
Bu dönüşüm sayısal, boole, metin DateTime ve anahtar veri türleri üzerinde çalışır.
- outputKind
- DataKind
Beklenen çıkış sütunu türü.
Döndürülenler
Örnekler
using System;
using Microsoft.ML;
using Microsoft.ML.Data;
namespace Samples.Dynamic
{
public static class ConvertType
{
public static void Example()
{
var mlContext = new MLContext(seed: 1);
var rawData = new[] {
new InputData() { Survived = true },
new InputData() { Survived = false },
new InputData() { Survived = true },
new InputData() { Survived = false },
new InputData() { Survived = false },
};
var data = mlContext.Data.LoadFromEnumerable(rawData);
// Construct the pipeline.
var pipeline = mlContext.Transforms.Conversion.ConvertType(
"SurvivedInt32", "Survived", DataKind.Int32);
// Let's train our pipeline, and then apply it to the same data.
var transformer = pipeline.Fit(data);
var transformedData = transformer.Transform(data);
// Display original column 'Survived' (boolean) and converted column
// SurvivedInt32' (Int32)
var convertedData = mlContext.Data.CreateEnumerable<TransformedData>(
transformedData, true);
foreach (var item in convertedData)
{
Console.WriteLine("A:{0,-10} Aconv:{1}", item.Survived,
item.SurvivedInt32);
}
// Output
// A: True Aconv:1
// A: False Aconv:0
// A: True Aconv:1
// A: False Aconv:0
// A: False Aconv:0
}
private class InputData
{
public bool Survived;
}
private sealed class TransformedData : InputData
{
public Int32 SurvivedInt32 { get; set; }
}
}
}
Şunlara uygulanır
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin