NormalizationCatalog.NormalizeGlobalContrast 方法

定义

创建一个 GlobalContrastNormalizingEstimator,用于对单独应用全局对比度规范化的列进行规范化。 true设置为 ensureZeroMean ,将应用预处理步骤,使指定的列的平均值为零向量。

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

要规范化的列的名称。 If set to null, the value of the outputColumnName will be used as source. 此估算器对已知大小的向量 Single进行操作。

ensureZeroMean
Boolean

如果在 true规范化之前从每个值中减去平均值,则使用原始输入;否则使用原始输入。

ensureUnitStandardDeviation
Boolean

如果 true,生成的向量的标准偏差将是一个。 否则,生成的向量的 L2 规范将是一个。

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

适用于