ExtensionsCatalog.ReplaceMissingValues 메서드

정의

오버로드

ReplaceMissingValues(TransformsCatalog, InputOutputColumnPair[], MissingValueReplacingEstimator+ReplacementMode, Boolean)

ColumnCopyingEstimator에 지정된 열에서 새 OutputColumnName 열로 데이터를 복사하고 그에 따라 replacementMode누락된 InputColumnName 값을 대체하는 를 만듭니다.

ReplaceMissingValues(TransformsCatalog, String, String, MissingValueReplacingEstimator+ReplacementMode, Boolean)

MissingValueReplacingEstimator에 지정된 열에서 새 outputColumnName 열로 데이터를 복사하고 그에 따라 replacementMode누락된 inputColumnName 값을 대체하는 를 만듭니다.

ReplaceMissingValues(TransformsCatalog, InputOutputColumnPair[], MissingValueReplacingEstimator+ReplacementMode, Boolean)

ColumnCopyingEstimator에 지정된 열에서 새 OutputColumnName 열로 데이터를 복사하고 그에 따라 replacementMode누락된 InputColumnName 값을 대체하는 를 만듭니다.

public static Microsoft.ML.Transforms.MissingValueReplacingEstimator ReplaceMissingValues (this Microsoft.ML.TransformsCatalog catalog, Microsoft.ML.InputOutputColumnPair[] columns, Microsoft.ML.Transforms.MissingValueReplacingEstimator.ReplacementMode replacementMode = Microsoft.ML.Transforms.MissingValueReplacingEstimator+ReplacementMode.DefaultValue, bool imputeBySlot = true);
static member ReplaceMissingValues : Microsoft.ML.TransformsCatalog * Microsoft.ML.InputOutputColumnPair[] * Microsoft.ML.Transforms.MissingValueReplacingEstimator.ReplacementMode * bool -> Microsoft.ML.Transforms.MissingValueReplacingEstimator
<Extension()>
Public Function ReplaceMissingValues (catalog As TransformsCatalog, columns As InputOutputColumnPair(), Optional replacementMode As MissingValueReplacingEstimator.ReplacementMode = Microsoft.ML.Transforms.MissingValueReplacingEstimator+ReplacementMode.DefaultValue, Optional imputeBySlot As Boolean = true) As MissingValueReplacingEstimator

매개 변수

catalog
TransformsCatalog

변환의 카탈로그입니다.

columns
InputOutputColumnPair[]

입력 및 출력 열 쌍입니다. 이 추정기는 부동 소수 자릿수 또는 이중의 스칼라 또는 벡터에서 작동합니다.

replacementMode
MissingValueReplacingEstimator.ReplacementMode

지정된 대로 사용할 대체 유형입니다. MissingValueReplacingEstimator.ReplacementMode

imputeBySlot
Boolean

이 경우 true슬롯당 대체가 수행됩니다. 그렇지 않으면 전체 벡터 열에 대한 대체 값이 대체됩니다. 이 설정은 스칼라 및 변수 벡터에 대해 무시됩니다. 여기서 전체 열에 대한 대체는 항상 적용됩니다.

반환

예제

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

namespace Samples.Dynamic
{
    class ReplaceMissingValuesMultiColumn
    {
        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();

            // Get a small dataset as an IEnumerable and convert it to an IDataView.
            var samples = new List<DataPoint>()
            {
                new DataPoint(){ Features1 = new float[3] {1, 1, 0}, Features2 =
                    new float[2] {1, 1} },

                new DataPoint(){ Features1 = new float[3] {0, float.NaN, 1},
                    Features2 = new float[2] {0, 1} },

                new DataPoint(){ Features1 = new float[3] {-1, float.NaN, -3},
                    Features2 = new float[2] {-1, float.NaN} },

                new DataPoint(){ Features1 = new float[3] {-1, 6, -3}, Features2 =
                    new float[2] {0, float.PositiveInfinity} },
            };
            var data = mlContext.Data.LoadFromEnumerable(samples);

            // Here we use the default replacement mode, which replaces the value
            // with the default value for its type.
            var defaultPipeline = mlContext.Transforms.ReplaceMissingValues(new[] {
                new InputOutputColumnPair("MissingReplaced1", "Features1"),
                new InputOutputColumnPair("MissingReplaced2", "Features2")
            },
            MissingValueReplacingEstimator.ReplacementMode.DefaultValue);

            // 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 defaultTransformer = defaultPipeline.Fit(data);
            var defaultTransformedData = defaultTransformer.Transform(data);

            // We can extract the newly created column as an IEnumerable of
            // SampleDataTransformed, the class we define below.
            var defaultRowEnumerable = mlContext.Data.CreateEnumerable<
                SampleDataTransformed>(defaultTransformedData, reuseRowObject:
                false);

            // And finally, we can write out the rows of the dataset, looking at the
            // columns of interest.
            foreach (var row in defaultRowEnumerable)
                Console.WriteLine("Features1: [" + string.Join(", ", row
                    .Features1) + "]\t MissingReplaced1: [" + string.Join(", ", row
                    .MissingReplaced1) + "]\t Features2: [" + string.Join(", ", row
                    .Features2) + "]\t MissingReplaced2: [" + string.Join(", ", row
                    .MissingReplaced2) + "]");

            // Expected output:
            // Features1: [1, 1, 0]     MissingReplaced1: [1, 1, 0]     Features2: [1, 1]       MissingReplaced2: [1, 1]
            // Features1: [0, NaN, 1]   MissingReplaced1: [0, 0, 1]     Features2: [0, 1]       MissingReplaced2: [0, 1]
            // Features1: [-1, NaN, -3]         MissingReplaced1: [-1, 0, -3]   Features2: [-1, NaN]    MissingReplaced2: [-1, 0]
            // Features1: [-1, 6, -3]   MissingReplaced1: [-1, 6, -3]   Features2: [0, ∞]       MissingReplaced2: [0, ∞]

            // Here we use the mean replacement mode, which replaces the value with
            // the mean of the non values that were not missing.
            var meanPipeline = mlContext.Transforms.ReplaceMissingValues(new[] {
                new InputOutputColumnPair("MissingReplaced1", "Features1"),
                new InputOutputColumnPair("MissingReplaced2", "Features2")
            },
            MissingValueReplacingEstimator.ReplacementMode.Mean);

            // 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 meanTransformer = meanPipeline.Fit(data);
            var meanTransformedData = meanTransformer.Transform(data);

            // We can extract the newly created column as an IEnumerable of
            // SampleDataTransformed, the class we define below.
            var meanRowEnumerable = mlContext.Data.CreateEnumerable<
                SampleDataTransformed>(meanTransformedData, reuseRowObject: false);

            // And finally, we can write out the rows of the dataset, looking at the
            // columns of interest.
            foreach (var row in meanRowEnumerable)
                Console.WriteLine("Features1: [" + string.Join(", ", row
                    .Features1) + "]\t MissingReplaced1: [" + string.Join(", ", row
                    .MissingReplaced1) + "]\t Features2: [" + string.Join(", ", row
                    .Features2) + "]\t MissingReplaced2: [" + string.Join(", ", row
                    .MissingReplaced2) + "]");

            // Expected output:
            // Features1: [1, 1, 0]     MissingReplaced1: [1, 1, 0]     Features2: [1, 1]       MissingReplaced2: [1, 1]
            // Features1: [0, NaN, 1]   MissingReplaced1: [0, 3.5, 1]   Features2: [0, 1]       MissingReplaced2: [0, 1]
            // Features1: [-1, NaN, -3]         MissingReplaced1: [-1, 3.5, -3]         Features2: [-1, NaN]    MissingReplaced2: [-1, 1]
            // Features1: [-1, 6, -3]   MissingReplaced1: [-1, 6, -3]   Features2: [0, ∞]       MissingReplaced2: [0, ∞]
        }

        private class DataPoint
        {
            [VectorType(3)]
            public float[] Features1 { get; set; }
            [VectorType(2)]
            public float[] Features2 { get; set; }
        }

        private sealed class SampleDataTransformed : DataPoint
        {
            [VectorType(3)]
            public float[] MissingReplaced1 { get; set; }
            [VectorType(2)]
            public float[] MissingReplaced2 { get; set; }
        }
    }
}

설명

이 변환은 여러 열에서 작동할 수 있습니다.

적용 대상

ReplaceMissingValues(TransformsCatalog, String, String, MissingValueReplacingEstimator+ReplacementMode, Boolean)

MissingValueReplacingEstimator에 지정된 열에서 새 outputColumnName 열로 데이터를 복사하고 그에 따라 replacementMode누락된 inputColumnName 값을 대체하는 를 만듭니다.

public static Microsoft.ML.Transforms.MissingValueReplacingEstimator ReplaceMissingValues (this Microsoft.ML.TransformsCatalog catalog, string outputColumnName, string inputColumnName = default, Microsoft.ML.Transforms.MissingValueReplacingEstimator.ReplacementMode replacementMode = Microsoft.ML.Transforms.MissingValueReplacingEstimator+ReplacementMode.DefaultValue, bool imputeBySlot = true);
static member ReplaceMissingValues : Microsoft.ML.TransformsCatalog * string * string * Microsoft.ML.Transforms.MissingValueReplacingEstimator.ReplacementMode * bool -> Microsoft.ML.Transforms.MissingValueReplacingEstimator
<Extension()>
Public Function ReplaceMissingValues (catalog As TransformsCatalog, outputColumnName As String, Optional inputColumnName As String = Nothing, Optional replacementMode As MissingValueReplacingEstimator.ReplacementMode = Microsoft.ML.Transforms.MissingValueReplacingEstimator+ReplacementMode.DefaultValue, Optional imputeBySlot As Boolean = true) As MissingValueReplacingEstimator

매개 변수

catalog
TransformsCatalog

변환의 카탈로그입니다.

outputColumnName
String

의 변환에서 생성된 열의 inputColumnName이름입니다. 이 열의 데이터 형식은 입력 열의 데이터 형식과 동일합니다.

inputColumnName
String

데이터를 복사할 열의 이름입니다. 이 추정기는 스칼라 또는 벡터 또는 벡터에 SingleDouble대해 작동합니다.

replacementMode
MissingValueReplacingEstimator.ReplacementMode

지정된 대로 사용할 대체 유형입니다. MissingValueReplacingEstimator.ReplacementMode

imputeBySlot
Boolean

true이면 슬롯당 대체가 수행됩니다. 그렇지 않으면 전체 벡터 열에 대한 대체 값이 대체됩니다. 이 설정은 스칼라 및 변수 벡터에 대해 무시됩니다. 여기서 전체 열에 대한 대체는 항상 적용됩니다.

반환

예제

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

namespace Samples.Dynamic
{
    class ReplaceMissingValues
    {
        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();

            // Get a small dataset as an IEnumerable and convert it to an IDataView.
            var samples = new List<DataPoint>()
            {
                new DataPoint(){ Features = new float[3] {float.PositiveInfinity, 1,
                    0 } },

                new DataPoint(){ Features = new float[3] {0, float.NaN, 1} },
                new DataPoint(){ Features = new float[3] {-1, 2, -3} },
                new DataPoint(){ Features = new float[3] {-1, float.NaN, -3} },
            };
            var data = mlContext.Data.LoadFromEnumerable(samples);

            // Here we use the default replacement mode, which replaces the value
            // with the default value for its type.
            var defaultPipeline = mlContext.Transforms.ReplaceMissingValues(
                "MissingReplaced", "Features", MissingValueReplacingEstimator
                .ReplacementMode.DefaultValue);

            // 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 defaultTransformer = defaultPipeline.Fit(data);
            var defaultTransformedData = defaultTransformer.Transform(data);

            // We can extract the newly created column as an IEnumerable of
            // SampleDataTransformed, the class we define below.
            var defaultRowEnumerable = mlContext.Data.CreateEnumerable<
                SampleDataTransformed>(defaultTransformedData, reuseRowObject:
                false);

            // And finally, we can write out the rows of the dataset, looking at the
            // columns of interest.
            foreach (var row in defaultRowEnumerable)
                Console.WriteLine("Features: [" + string.Join(", ", row.Features) +
                    "]\t MissingReplaced: [" + string.Join(", ", row
                    .MissingReplaced) + "]");

            // Expected output:
            // Features: [∞, 1, 0]      MissingReplaced: [∞, 1, 0]
            // Features: [0, NaN, 1]    MissingReplaced: [0, 0, 1]
            // Features: [-1, 2, -3]    MissingReplaced: [-1, 2, -3]
            // Features: [-1, NaN, -3]  MissingReplaced: [-1, 0, -3]

            // Here we use the mean replacement mode, which replaces the value with
            // the mean of the non values that were not missing.
            var meanPipeline = mlContext.Transforms.ReplaceMissingValues(
                "MissingReplaced", "Features", MissingValueReplacingEstimator
                .ReplacementMode.Mean);

            // 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 meanTransformer = meanPipeline.Fit(data);
            var meanTransformedData = meanTransformer.Transform(data);

            // We can extract the newly created column as an IEnumerable of
            // SampleDataTransformed, the class we define below.
            var meanRowEnumerable = mlContext.Data.CreateEnumerable<
                SampleDataTransformed>(meanTransformedData, reuseRowObject: false);

            // And finally, we can write out the rows of the dataset, looking at the
            // columns of interest.
            foreach (var row in meanRowEnumerable)
                Console.WriteLine("Features: [" + string.Join(", ", row.Features) +
                    "]\t MissingReplaced: [" + string.Join(", ", row
                    .MissingReplaced) + "]");

            // Expected output:
            // Features: [∞, 1, 0]      MissingReplaced: [∞, 1, 0]
            // Features: [0, NaN, 1]    MissingReplaced: [0, 1.5, 1]
            // Features: [-1, 2, -3]    MissingReplaced: [-1, 2, -3]
            // Features: [-1, NaN, -3]  MissingReplaced: [-1, 1.5, -3]
        }

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

        private sealed class SampleDataTransformed : DataPoint
        {
            [VectorType(3)]
            public float[] MissingReplaced { get; set; }
        }
    }
}

적용 대상