KernelExpansionCatalog.ApproximatedKernelMap 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 , ApproximatedKernelMappingEstimator 將輸入向量對應至低維度特徵空間,其中內部產品大約是移位不變數核心函式。
public static Microsoft.ML.Transforms.ApproximatedKernelMappingEstimator ApproximatedKernelMap (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName = default, int rank = 1000, bool useCosAndSinBases = false, Microsoft.ML.Transforms.KernelBase generator = default, int? seed = default);
static member ApproximatedKernelMap : Microsoft.ML.TransformsCatalog * string * string * int * bool * Microsoft.ML.Transforms.KernelBase * Nullable<int> -> Microsoft.ML.Transforms.ApproximatedKernelMappingEstimator
<Extension()>
Public Function ApproximatedKernelMap (catalog As TransformsCatalog, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional rank As Integer = 1000, Optional useCosAndSinBases As Boolean = false, Optional generator As KernelBase = Nothing, Optional seed As Nullable(Of Integer) = Nothing) As ApproximatedKernelMappingEstimator
參數
- catalog
- TransformsCatalog
轉換的目錄。
- inputColumnName
- String
要轉換的資料行名稱。 如果設定為 null
,則會 outputColumnName
將 的值當做來源使用。
此估算器會在資料類型的 Single 已知大小向量上運作。
- rank
- Int32
要對應輸入的功能空間維度。
- useCosAndSinBases
- Boolean
如果 true
為 ,請使用 cos 和 sin basis 函式,為每個隨機的 Fourier 頻率建立兩個特徵。 否則,只會使用 cos 基底。 請注意,如果設定為 true
,輸出特徵空間的維度會是 2* rank
。
- generator
- KernelBase
指出要使用哪一個核心的引數。 這兩個可用的實作為 GaussianKernel 和 LaplacianKernel 。
傳回
範例
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.Transforms;
namespace Samples.Dynamic
{
public static class ApproximatedKernelMap
{
// Transform feature vector to another non-linear space. See
// https://people.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf.
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();
var samples = new List<DataPoint>()
{
new DataPoint(){ Features = new float[7] { 1, 1, 0, 0, 1, 0, 1} },
new DataPoint(){ Features = new float[7] { 0, 0, 1, 0, 0, 1, 1} },
new DataPoint(){ Features = new float[7] {-1, 1, 0,-1,-1, 0,-1} },
new DataPoint(){ Features = new float[7] { 0,-1, 0, 1, 0,-1,-1} }
};
// Convert training data to IDataView, the general data type used in
// ML.NET.
var data = mlContext.Data.LoadFromEnumerable(samples);
// ApproximatedKernel map takes data and maps it's to a random
// low -dimensional space.
var approximation = mlContext.Transforms.ApproximatedKernelMap(
"Features", rank: 4, generator: new GaussianKernel(gamma: 0.7f),
seed: 1);
// Now we can transform the data and look at the output to confirm the
// behavior of the estimator. This operation doesn't actually evaluate
// data until we read the data below.
var tansformer = approximation.Fit(data);
var transformedData = tansformer.Transform(data);
var column = transformedData.GetColumn<float[]>("Features").ToArray();
foreach (var row in column)
Console.WriteLine(string.Join(", ", row.Select(x => x.ToString(
"f4"))));
// Expected output:
// -0.0119, 0.5867, 0.4942, 0.7041
// 0.4720, 0.5639, 0.4346, 0.2671
// -0.2243, 0.7071, 0.7053, -0.1681
// 0.0846, 0.5836, 0.6575, 0.0581
}
private class DataPoint
{
[VectorType(7)]
public float[] Features { get; set; }
}
}
}