Bagikan melalui


NormalizationCatalog.NormalizeGlobalContrast Metode

Definisi

Buat GlobalContrastNormalizingEstimator, yang menormalkan kolom secara individual menerapkan normalisasi kontras global. Pengaturan ensureZeroMean ke true, akan menerapkan langkah pra-pemrosesan untuk membuat rata-rata kolom yang ditentukan menjadi vektor nol.

public static Microsoft.ML.Transforms.GlobalContrastNormalizingEstimator NormalizeGlobalContrast(this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName = default, bool ensureZeroMean = true, bool ensureUnitStandardDeviation = false, float scale = 1);
static member NormalizeGlobalContrast : Microsoft.ML.TransformsCatalog * string * string * bool * bool * single -> Microsoft.ML.Transforms.GlobalContrastNormalizingEstimator
<Extension()>
Public Function NormalizeGlobalContrast (catalog As TransformsCatalog, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional ensureZeroMean As Boolean = true, Optional ensureUnitStandardDeviation As Boolean = false, Optional scale As Single = 1) As GlobalContrastNormalizingEstimator

Parameter

catalog
TransformsCatalog

Katalog transformasi.

outputColumnName
String

Nama kolom yang dihasilkan dari transformasi inputColumnName. Jenis data kolom ini akan sama dengan jenis data kolom input.

inputColumnName
String

Nama kolom yang akan dinormalisasi. Jika diatur ke null, nilai outputColumnName akan digunakan sebagai sumber. Estimator ini beroperasi atas vektor berukuran besar yang diketahui dari Single.

ensureZeroMean
Boolean

Jika true, kurangi rata-rata dari setiap nilai sebelum menormalkan dan menggunakan input mentah sebaliknya.

ensureUnitStandardDeviation
Boolean

Jika true, simpang siur standar vektor yang dihasilkan akan menjadi satu. Jika tidak, vektor yang dihasilkan L2-norma akan menjadi satu.

scale
Single

Menskalakan fitur dengan nilai ini.

Mengembalikan

Contoh

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

namespace Samples.Dynamic
{
    class NormalizeGlobalContrast
    {
        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.NormalizeGlobalContrast(
                "Features", ensureZeroMean: false, scale: 2,
                ensureUnitStandardDeviation: 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:
            //  2.0000, 2.0000,-2.0000,-2.0000
            //  2.0000, 2.0000,-2.0000,-2.0000
            //  2.0000,-2.0000, 2.0000,-2.0000
            //- 2.0000, 2.0000,-2.0000, 2.0000
        }

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

Berlaku untuk