NormalizationCatalog.NormalizeLpNorm Metoda

Definice

Vytvořte LpNormNormalizingEstimatorvektory , které normalizuje (škáluje) ve vstupním sloupci na jednotkovou normu. Typ normy, která se používá, je definována .norm Nastavení na hodnotu < a0/> použije krok předběžného zpracování, aby byl střední hodnota zadaného sloupce nulovým vektorem.

public static Microsoft.ML.Transforms.LpNormNormalizingEstimator NormalizeLpNorm(this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName = default, Microsoft.ML.Transforms.LpNormNormalizingEstimatorBase.NormFunction norm = Microsoft.ML.Transforms.LpNormNormalizingEstimatorBase+NormFunction.L2, bool ensureZeroMean = false);
static member NormalizeLpNorm : Microsoft.ML.TransformsCatalog * string * string * Microsoft.ML.Transforms.LpNormNormalizingEstimatorBase.NormFunction * bool -> Microsoft.ML.Transforms.LpNormNormalizingEstimator
<Extension()>
Public Function NormalizeLpNorm (catalog As TransformsCatalog, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional norm As LpNormNormalizingEstimatorBase.NormFunction = Microsoft.ML.Transforms.LpNormNormalizingEstimatorBase+NormFunction.L2, Optional ensureZeroMean As Boolean = false) As LpNormNormalizingEstimator

Parametry

catalog
TransformsCatalog

Katalog transformace.

outputColumnName
String

Název sloupce, který je výsledkem transformace inputColumnName. Datový typ tohoto sloupce bude stejný jako datový typ vstupního sloupce.

inputColumnName
String

Název sloupce, který se má normalizovat. Pokud je nastavená null hodnota outputColumnName, použije se jako zdroj. Tento estimátor pracuje s vektory Singleznámé velikosti .

norm
LpNormNormalizingEstimatorBase.NormFunction

Typ normy, která se má použít k normalizaci každého vzorku. Uvedená norma výsledného vektoru bude normalizována na jednu.

ensureZeroMean
Boolean

Pokud trueodečtěte střední hodnotu od každé hodnoty před normalizací a v opačném případě použijte nezpracovaný vstup.

Návraty

Příklady

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

namespace Samples.Dynamic
{
    class NormalizeLpNorm
    {
        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[4] { 1, 1, 0, 0} },
                new DataPoint(){ Features = new float[4] { 2, 2, 0, 0} },
                new DataPoint(){ Features = new float[4] { 1, 0, 1, 0} },
                new DataPoint(){ Features = new float[4] { 0, 1, 0, 1} }
            };
            // Convert training data to IDataView, the general data type used in
            // ML.NET.
            var data = mlContext.Data.LoadFromEnumerable(samples);
            var approximation = mlContext.Transforms.NormalizeLpNorm("Features",
                norm: LpNormNormalizingEstimatorBase.NormFunction.L1,
                ensureZeroMean: true);

            // 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.2500,  0.2500, -0.2500, -0.2500
            //  0.2500,  0.2500, -0.2500, -0.2500
            //  0.2500, -0.2500,  0.2500, -0.2500
            // -0.2500,  0.2500, -0.2500,  0.2500
        }

        private class DataPoint
        {
            [VectorType(4)]
            public float[] Features { get; set; }
        }
    }
}

Platí pro