NormalizationCatalog.NormalizeGlobalContrast 方法

定義

建立 , GlobalContrastNormalizingEstimator 將個別套用全域對比正規化的資料行正規化。 將 設定 ensureZeroMeantrue ,將會套用前置處理步驟,讓指定的資料行平均值成為零向量。

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

參數

catalog
TransformsCatalog

轉換的目錄。

outputColumnName
String

轉換所產生的 inputColumnName 資料行名稱。 此資料行的資料類型會與輸入資料行的資料類型相同。

inputColumnName
String

要正規化的資料行名稱。 如果設定為 null ,則會將 的值 outputColumnName 當做來源使用。 此估算器會透過 的 Single 已知大小向量運作。

ensureZeroMean
Boolean

如果 true 為 ,請在正規化之前從每個值減去平均值,否則使用原始輸入。

ensureUnitStandardDeviation
Boolean

如果 true 為 ,則產生的向量標準差會是一個。 否則,產生的向量 L2-norm 會是其中一個。

scale
Single

依此值調整功能。

傳回

範例

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; }
        }
    }
}

適用於