Main Content

observationImputerComponent

Pipeline component for imputing missing values

Since R2026a

    Description

    observationImputerComponent is a pipeline component that imputes missing values in data observations. The pipeline component identifies and imputes missing values for a set of observations during the learn phase. During the run phase, the component uses the values learned during the learn phase to impute missing values in new observations.

    Creation

    Description

    component = observationImputerComponent creates a pipeline component for imputing missing values.

    example

    component = observationImputerComponent(Name=Value) sets writable Properties using one or more name-value arguments. For example, you can specify the imputation method by using the Method name-value argument.

    Properties

    expand all

    Learn Parameters

    The software sets learn parameters when you create the component. You can modify learn parameters using dot notation any time before you use the learn object function. Any unset learn parameters use the corresponding default values.

    Imputation method, specified as "mean", "median", or "mode".

    ValueDescription
    "mean"For each variable, replace the missing values with the average (mean) value. This method is not supported for categorical variables.
    "median"For each variable, replace the missing values with the median value. This method is not supported for categorical variables.
    "mode"For each variable, replace the missing values with the value that appears most frequently in the variable.

    If you do not specify the Method value, the software uses "median" for numeric variables and "mode" for categorical variables.

    Example: c = observationImputerComponent(Method="mean")

    Example: c.Method = "mode"

    Data Types: char | string

    Component Properties

    The software sets component properties when you create the component. You can modify the component properties (excluding HasLearnables and HasLearned) using dot notation at any time. You cannot modify the HasLearnables and HasLearned properties directly.

    Component identifier, specified as a character vector or string scalar.

    Example: c = observationImputerComponent(Name="Imputation")

    Example: c.Name = "Impute"

    Data Types: char | string

    Names of the input ports, specified as a character vector, string array, or cell array of character vectors.

    Example: c = observationImputerComponent(Inputs="X")

    Example: c.Inputs = "X1"

    Data Types: char | string | cell

    Names of the output ports, specified as a character vector, string array, or cell array of character vectors.

    Example: c = observationImputerComponent(Outputs="FilledX")

    Example: c.Outputs = "FilledX1"

    Data Types: char | string | cell

    Tags that enable the automatic connection of the component inputs with other components or pipelines, specified as a nonnegative integer vector. If you specify InputTags, the number of tags must match the number of inputs in Inputs.

    Example: c = observationImputerComponent(InputTags=0)

    Example: c.InputTags = 1

    Data Types: single | double

    Tags that enable the automatic connection of the component outputs with other components or pipelines, specified as a nonnegative integer vector. If you specify OutputTags, the number of tags must match the number of outputs in Outputs.

    Example: c = observationImputerComponent(OutputTags=0)

    Example: c.OutputTags = 1

    Data Types: single | double

    This property is read-only.

    Indicator for the learnables, returned as 1 (true). A value of 1 indicates that the component contains Learnables.

    Data Types: logical

    This property is read-only.

    Indicator showing the learning status of the component, returned as 0 (false) or 1 (true). A value of 1 indicates that the learn object function has been applied to the component, and the Learnables are nonempty.

    Data Types: logical

    Learnables

    The software sets learnables when you use the learn object function. You cannot modify learnables directly.

    This property is read-only.

    Learned values to use for imputation, returned as a cell array. Each value corresponds to a variable in ImputedVariables.

    This property is read-only.

    Names of the variables used by the component to derive ImputedValues, returned as a string array. The variables correspond to columns in the data argument of learn.

    Data Types: string

    Object Functions

    learnInitialize and evaluate pipeline or component
    runExecute pipeline or component for inference after learning
    resetReset pipeline or component
    seriesConnect components in series to create pipeline
    parallelConnect components or pipelines in parallel to create pipeline
    viewView diagram of pipeline inputs, outputs, components, and connections

    Examples

    collapse all

    Create a pipeline component that imputes missing values in observations.

    component = observationImputerComponent
    component = 
    
      observationImputerComponent with properties:
    
                    Name: "ObservationImputer"
                  Inputs: "DataIn"
               InputTags: 1
                 Outputs: "DataOut"
              OutputTags: 1
    
       
    Learnables (HasLearned = false)
        ImputedVariables: []
           ImputedValues: []
    
    
    Show all parameters

    component is an observationImputerComponent object that contains two learnables: ImputedVariables and ImputedValues. The properties remain empty until you pass data to the component during the learn phase.

    Load the carbig data set. Create a table containing the variables Acceleration, Displacement, and Horsepower.

    load carbig
    cars = table(Acceleration,Displacement,Horsepower);

    Note that the Horsepower variable contains missing values. For example, display the 338th observation in cars.

    observation = cars(338,:)
    observation =
    
      1×3 table
    
        Acceleration    Displacement    Horsepower
        ____________    ____________    __________
    
            17.3             85            NaN    

    Use the learn object function to find and impute missing values in cars.

    [component,newcars] = learn(component,cars);
    component
    component = 
    
      observationImputerComponent with properties:
    
                    Name: "ObservationImputer"
                  Inputs: "DataIn"
               InputTags: 1
                 Outputs: "DataOut"
              OutputTags: 1
    
       
    Learnables (HasLearned = true)
        ImputedVariables: ["Acceleration"    "Displacement"    "Horsepower"]
           ImputedValues: {[15.5000]  [151]  [95]}
    
    
    Show all parameters

    The ImputedVariables and ImputedValues properties are nonempty, and the HasLearned property is set to true.

    Note that the 338th observation in newcars uses the imputed Horsepower value of 95.

    newObservation = newcars(338,:)
    newObservation =
    
      1×3 table
    
        Acceleration    Displacement    Horsepower
        ____________    ____________    __________
    
            17.3             85             95    

    Version History

    Introduced in R2026a

    See Also

    | |