주요 콘텐츠

variableSelectorComponent

Pipeline component for manual variable selection

Since R2026a

    Description

    variableSelectorComponent is a pipeline component that selects variables manually. During the learn phase, the pipeline component identifies the variables to select. During the run phase, the component selects the learned variables from new data.

    Creation

    Description

    component = variableSelectorComponent creates a pipeline component for manually selecting variables.

    component = variableSelectorComponent(Name=Value) sets writable Properties using one or more name-value arguments. For example, DataType="categorical" specifies to select variables containing categorical data.

    example

    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.

    Data type of variables to select, specified as "likenum", "numeric", "categorical", "likecategorical", "string", or "datetime". The component selects variables that contain data of type DataType.

    If you specify both DataType and VariableNames, the component selects variables that meet either criteria.

    Example: c = variableSelectorComponent(DataType="categorical")

    Example: c.DataType = "string"

    Data Types: char | string

    Names of variables to select, specified as a string array, character vector, or cell array of character vectors.

    If you specify both VariableNames and DataType, the component selects variables that meet either criteria.

    Example: c = variableSelectorComponent(VariableNames=["X" "Y"])

    Example: c.VariableNames = ["Var1" "Var2" "Var4"]

    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 = variableSelectorComponent(Name="SelectVariables")

    Example: c.Name = "SelectX"

    Data Types: char | string

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

    Example: c = variableSelectorComponent(Inputs="Data1")

    Example: c.Inputs = "X"

    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 = variableSelectorComponent(Outputs="newX")

    Example: c.Outputs = "X"

    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, then the number of tags must match the number of inputs in Inputs.

    Example: c = variableSelectorComponent(InputTags=2)

    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, then the number of tags must match the number of outputs in Outputs.

    Example: c = variableSelectorComponent(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.

    Names of the features selected by the component, returned as a cell array. The features correspond to columns in the first data argument of learn.

    Data Types: cell

    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 variableSelectorComponent pipeline component. Specify to select categorical data.

    component = variableSelectorComponent(DataType="categorical")
    component = 
      variableSelectorComponent with properties:
    
                     Name: "VariableSelector"
                   Inputs: "DataIn"
                InputTags: 1
                  Outputs: "DataSelected"
               OutputTags: 1
    
       
    Learnables (HasLearned = false)
        SelectedVariables: []
    
       
    Learn Parameters (unlocked)
                 DataType: "categorical"
    
    
    Show all parameters
    

    component is a variableSelectorComponent object that contains one learnable, SelectedVariables. This property remains empty until you pass data to the component during the learn phase.

    Load the census1994 data set. Store the predictor and response data in the tables X and Y, respectively. The predictor data contains 14 variables.

    load census1994
    X = adultdata(:,1:end-1);
    Y = adultdata(:,end);

    Use the learn object function to select the categorical features from the predictor data X.

    component = learn(component,X)
    component = 
      variableSelectorComponent with properties:
    
                     Name: "VariableSelector"
                   Inputs: "DataIn"
                InputTags: 1
                  Outputs: "DataSelected"
               OutputTags: 1
    
       
    Learnables (HasLearned = true)
        SelectedVariables: {8×1 cell}
    
       
    Learn Parameters (locked)
                 DataType: {'categorical'}
    
    
    Show all parameters
    

    Note that the HasLearned property is set to true and SelectedVariables is nonempty.

    Find the names of the selected features.

    names = component.SelectedVariables
    names =
    
      8×1 cell array
    
        {'education'     }
        {'marital_status'}
        {'native_country'}
        {'occupation'    }
        {'race'          }
        {'relationship'  }
        {'sex'           }
        {'workClass'     }

    Version History

    Introduced in R2026a