CategoricalCatalog.OneHotHashEncoding Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Überlädt
| Name | Beschreibung |
|---|---|
| OneHotHashEncoding(TransformsCatalog+CategoricalTransforms, InputOutputColumnPair[], OneHotEncodingEstimator+OutputKind, Int32, UInt32, Boolean, Int32) |
Erstellen Sie eine OneHotHashEncodingEstimator, die eine oder mehrere Eingabetextspalten konvertiert, die durch |
| OneHotHashEncoding(TransformsCatalog+CategoricalTransforms, String, String, OneHotEncodingEstimator+OutputKind, Int32, UInt32, Boolean, Int32) |
Erstellen Sie eine OneHotHashEncodingEstimator, die eine Textspalte konvertiert, die durch |
OneHotHashEncoding(TransformsCatalog+CategoricalTransforms, InputOutputColumnPair[], OneHotEncodingEstimator+OutputKind, Int32, UInt32, Boolean, Int32)
- Quelle:
- CategoricalCatalog.cs
- Quelle:
- CategoricalCatalog.cs
- Quelle:
- CategoricalCatalog.cs
Erstellen Sie eine OneHotHashEncodingEstimator, die eine oder mehrere Eingabetextspalten konvertiert, die durch columns so viele Spalten mit Hash-basierten Vektoren mit einem hotcodierten Hash angegeben werden.
public static Microsoft.ML.Transforms.OneHotHashEncodingEstimator OneHotHashEncoding(this Microsoft.ML.TransformsCatalog.CategoricalTransforms catalog, Microsoft.ML.InputOutputColumnPair[] columns, Microsoft.ML.Transforms.OneHotEncodingEstimator.OutputKind outputKind = Microsoft.ML.Transforms.OneHotEncodingEstimator+OutputKind.Indicator, int numberOfBits = 16, uint seed = 314489979, bool useOrderedHashing = true, int maximumNumberOfInverts = 0);
static member OneHotHashEncoding : Microsoft.ML.TransformsCatalog.CategoricalTransforms * Microsoft.ML.InputOutputColumnPair[] * Microsoft.ML.Transforms.OneHotEncodingEstimator.OutputKind * int * uint32 * bool * int -> Microsoft.ML.Transforms.OneHotHashEncodingEstimator
<Extension()>
Public Function OneHotHashEncoding (catalog As TransformsCatalog.CategoricalTransforms, columns As InputOutputColumnPair(), Optional outputKind As OneHotEncodingEstimator.OutputKind = Microsoft.ML.Transforms.OneHotEncodingEstimator+OutputKind.Indicator, Optional numberOfBits As Integer = 16, Optional seed As UInteger = 314489979, Optional useOrderedHashing As Boolean = true, Optional maximumNumberOfInverts As Integer = 0) As OneHotHashEncodingEstimator
Parameter
Der Transformationskatalog
- columns
- InputOutputColumnPair[]
Die Paare von Eingabe- und Ausgabespalten. Der Datentyp der Ausgabespalten ist ein Vektor von Single if outputKind is Bag, Indicatorund Binary.
Wenn outputKind dies der Fall ist Key, ist der Datentyp der Ausgabespalten ein Schlüssel im Fall einer skalaren Eingabespalte oder eines Schlüsselvektors im Fall einer Vektoreingabespalte.
- outputKind
- OneHotEncodingEstimator.OutputKind
Der Konvertierungsmodus.
- numberOfBits
- Int32
Die Anzahl der Bits, in die ein Hash eingefügt werden soll. Muss zwischen 1 und 30 (einschließlich) liegen.
- seed
- UInt32
Hashing seed.
- useOrderedHashing
- Boolean
Gibt an, ob die Position der einzelnen Begriffe im Hash enthalten sein soll.
- maximumNumberOfInverts
- Int32
Während des Hashings haben wir Zuordnungen zwischen originalen Werten und den erzeugten Hashwerten hergestellt.
Die Textdarstellung von Originalwerten wird in den Slotnamen der Metadaten für die neue Spalte gespeichert. Hashing kann beispielsweise viele Anfangswerte einem zuordnen.
maximumNumberOfInverts Gibt die obere Grenze der Anzahl der unterschiedlichen Eingabewerte an, die einem Hash zugeordnet werden sollen, der beibehalten werden soll.
<gibt>"0</returns> " zurück, behält keine Eingabewerte bei.
<returns-1></returns> behält alle Eingabewerte bei, die jedem Hash zugeordnet sind.
Gibt zurück
Beispiele
using System;
using Microsoft.ML;
namespace Samples.Dynamic.Transforms.Categorical
{
public static class OneHotHashEncodingMultiColumn
{
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();
// Get a small dataset as an IEnumerable.
var samples = new[]
{
new DataPoint {Education = "0-5yrs", ZipCode = "98005"},
new DataPoint {Education = "0-5yrs", ZipCode = "98052"},
new DataPoint {Education = "6-11yrs", ZipCode = "98005"},
new DataPoint {Education = "6-11yrs", ZipCode = "98052"},
new DataPoint {Education = "11-15yrs", ZipCode = "98005"}
};
// Convert training data to IDataView.
IDataView data = mlContext.Data.LoadFromEnumerable(samples);
// Multi column example: A pipeline for one hot has encoding two
// columns 'Education' and 'ZipCode'.
var multiColumnKeyPipeline =
mlContext.Transforms.Categorical.OneHotHashEncoding(
new[]
{
new InputOutputColumnPair("Education"),
new InputOutputColumnPair("ZipCode")
},
numberOfBits: 3);
// Fit and Transform the data.
IDataView transformedData =
multiColumnKeyPipeline.Fit(data).Transform(data);
var convertedData =
mlContext.Data.CreateEnumerable<TransformedData>(transformedData,
true);
Console.WriteLine(
"One Hot Hash Encoding of two columns 'Education' and 'ZipCode'.");
// One Hot Hash Encoding of two columns 'Education' and 'ZipCode'.
foreach (TransformedData item in convertedData)
Console.WriteLine("{0}\t\t\t{1}", string.Join(" ", item.Education),
string.Join(" ", item.ZipCode));
// We have 8 slots, because we used numberOfBits = 3.
// 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
// 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0
// 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1
// 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0
// 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1
}
private class DataPoint
{
public string Education { get; set; }
public string ZipCode { get; set; }
}
private class TransformedData
{
public float[] Education { get; set; }
public float[] ZipCode { get; set; }
}
}
}
Hinweise
Wenn mehrere Spalten an die Schätzung übergeben werden, werden alle Spalten in einem einzigen Durchlauf über die Daten verarbeitet. Daher ist es effizienter, einen Schätzer mit vielen Spalten anzugeben, als viele Schätzzeichen mit einer einzelnen Spalte anzugeben.
Gilt für:
OneHotHashEncoding(TransformsCatalog+CategoricalTransforms, String, String, OneHotEncodingEstimator+OutputKind, Int32, UInt32, Boolean, Int32)
- Quelle:
- CategoricalCatalog.cs
- Quelle:
- CategoricalCatalog.cs
- Quelle:
- CategoricalCatalog.cs
Erstellen Sie eine OneHotHashEncodingEstimator, die eine Textspalte konvertiert, die durch inputColumnName eine Hash-basierte Vektorspalte mit einem Hot-codierten Vektor mit dem Namen angegeben outputColumnNamewird.
public static Microsoft.ML.Transforms.OneHotHashEncodingEstimator OneHotHashEncoding(this Microsoft.ML.TransformsCatalog.CategoricalTransforms catalog, string outputColumnName, string inputColumnName = default, Microsoft.ML.Transforms.OneHotEncodingEstimator.OutputKind outputKind = Microsoft.ML.Transforms.OneHotEncodingEstimator+OutputKind.Indicator, int numberOfBits = 16, uint seed = 314489979, bool useOrderedHashing = true, int maximumNumberOfInverts = 0);
static member OneHotHashEncoding : Microsoft.ML.TransformsCatalog.CategoricalTransforms * string * string * Microsoft.ML.Transforms.OneHotEncodingEstimator.OutputKind * int * uint32 * bool * int -> Microsoft.ML.Transforms.OneHotHashEncodingEstimator
<Extension()>
Public Function OneHotHashEncoding (catalog As TransformsCatalog.CategoricalTransforms, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional outputKind As OneHotEncodingEstimator.OutputKind = Microsoft.ML.Transforms.OneHotEncodingEstimator+OutputKind.Indicator, Optional numberOfBits As Integer = 16, Optional seed As UInteger = 314489979, Optional useOrderedHashing As Boolean = true, Optional maximumNumberOfInverts As Integer = 0) As OneHotHashEncodingEstimator
Parameter
Der Transformationskatalog.
- outputColumnName
- String
Name der Spalte, die sich aus der Transformation von inputColumnName.
Der Datentyp dieser Spalte ist ein Vektor von Single if outputKind is Bag, Indicatorund Binary.
Wenn outputKind dies der Fall ist Key, ist der Datentyp dieser Spalte ein Schlüssel im Falle einer skalaren Eingabespalte oder eines Schlüsselvektors im Falle einer Vektoreingabespalte.
- inputColumnName
- String
Name der zu transformierenden Spalte. Bei Festlegung auf null, wird der Wert des Werts outputColumnName als Quelle verwendet.
Der Datentyp dieser Spalte kann skalar oder Vektor numerischer, Text, DateTime boolescher Oder DateTimeOffset.
- outputKind
- OneHotEncodingEstimator.OutputKind
Der Konvertierungsmodus.
- numberOfBits
- Int32
Die Anzahl der Bits, in die ein Hash eingefügt werden soll. Muss zwischen 1 und 30 (einschließlich) liegen.
- seed
- UInt32
Hashing seed.
- useOrderedHashing
- Boolean
Gibt an, ob die Position der einzelnen Begriffe im Hash enthalten sein soll.
- maximumNumberOfInverts
- Int32
Während des Hashings haben wir Zuordnungen zwischen originalen Werten und den erzeugten Hashwerten hergestellt.
Die Textdarstellung von Originalwerten wird in den Slotnamen der Metadaten für die neue Spalte gespeichert. Hashing kann beispielsweise viele Anfangswerte einem zuordnen.
maximumNumberOfInverts Gibt die obere Grenze der Anzahl der unterschiedlichen Eingabewerte an, die einem Hash zugeordnet werden sollen, der beibehalten werden soll.
<gibt>"0</returns> " zurück, behält keine Eingabewerte bei.
<returns-1></returns> behält alle Eingabewerte bei, die jedem Hash zugeordnet sind.
Gibt zurück
Beispiele
using System;
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.Transforms;
namespace Samples.Dynamic.Transforms.Categorical
{
public static class OneHotHashEncoding
{
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[]
{
new DataPoint {Education = "0-5yrs"},
new DataPoint {Education = "0-5yrs"},
new DataPoint {Education = "6-11yrs"},
new DataPoint {Education = "6-11yrs"},
new DataPoint {Education = "11-15yrs"}
};
// Convert training data to an IDataView.
IDataView data = mlContext.Data.LoadFromEnumerable(samples);
// A pipeline for one hot hash encoding the 'Education' column.
var pipeline = mlContext.Transforms.Categorical.OneHotHashEncoding(
"EducationOneHotHashEncoded", "Education", numberOfBits: 3);
// Fit and transform the data.
IDataView hashEncodedData = pipeline.Fit(data).Transform(data);
PrintDataColumn(hashEncodedData, "EducationOneHotHashEncoded");
// We have 8 slots, because we used numberOfBits = 3.
// 0 0 0 1 0 0 0 0
// 0 0 0 1 0 0 0 0
// 0 0 0 0 1 0 0 0
// 0 0 0 0 1 0 0 0
// 0 0 0 0 0 0 0 1
// A pipeline for one hot hash encoding the 'Education' column
// (using keying strategy).
var keyPipeline = mlContext.Transforms.Categorical.OneHotHashEncoding(
"EducationOneHotHashEncoded", "Education",
OneHotEncodingEstimator.OutputKind.Key, 3);
// Fit and transform the data.
IDataView hashKeyEncodedData = keyPipeline.Fit(data).Transform(data);
// Get the data of the newly created column for inspecting.
var keyEncodedColumn =
hashKeyEncodedData.GetColumn<uint>("EducationOneHotHashEncoded");
Console.WriteLine(
"One Hot Hash Encoding of single column 'Education', with key " +
"type output.");
// One Hot Hash Encoding of single column 'Education', with key type output.
foreach (uint element in keyEncodedColumn)
Console.WriteLine(element);
// 4
// 4
// 5
// 5
// 8
}
private static void PrintDataColumn(IDataView transformedData,
string columnName)
{
var countSelectColumn = transformedData.GetColumn<float[]>(
transformedData.Schema[columnName]);
foreach (var row in countSelectColumn)
{
for (var i = 0; i < row.Length; i++)
Console.Write($"{row[i]}\t");
Console.WriteLine();
}
}
private class DataPoint
{
public string Education { get; set; }
}
}
}