Main Content

LearningPipeline

Machine learning pipeline

Since R2026a

    Description

    A LearningPipeline object is a container that holds and connects multiple steps (components) of a machine learning workflow as a direct acyclic graph (DAG). The pipeline components can contain data-dependent parameters, such as learnables. You can train a pipeline with training data and then use the trained pipeline for inference by passing new data through it. Create a pipeline by connecting one or more components or pipelines in series or in parallel.

    Creation

    You can create a pipeline using automatic or manual connections.

    • Automatic connections

      Create and change a pipeline automatically by using the series and parallel object functions. You can also use these functions to combine pipelines and components. For example, after creating three components c1, c2, and c3, you can specify p1 = series(c1,c2); p2 = series(p1,c3).

      The insert object function places components in a pipeline by automatically cutting and reconnecting the existing connections. The replace object function automatically makes the correct connections when the new and replaced components are compatible.

      Automatic creation functions automatically solve naming issues (such as having multiple components or pipeline ports with the same name) and connect the components.

      For more details on automatic connections, see Port Tags for Automatic Connection.

    • Manual connections

      p = LearningPipeline creates a pipeline without processing components or connections. You can build upon the pipeline by using the add, remove, connect, and disconnect object functions.

      The add and remove functions do not connect the newly added components or remaining components in the pipeline. After using add or remove, you must use the connect function to define connections.

    Properties

    expand all

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

    Identifier of the pipeline, specified as a character vector or string scalar.

    Data Types: char | string

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

    Data Types: char | string | cell

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

    Data Types: char | string | cell

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

    Data Types: single | double

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

    Data Types: single | double

    Pipeline components, specified as a structure where each field contains a component.

    Data Types: struct

    This property is read-only.

    Paths along which data passes between components, returned as a two-column table. Each row corresponds to a connection between two ports, a source and a destination. Data passes from the source to the destination.

    Data Types: table

    This property is read-only.

    Indicator for the learnables in the pipeline, returned as 0 (false) or 1 (true). A value of 1 indicates that the pipeline contains learnables in at least one component.

    Data Types: logical

    This property is read-only.

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

    Data Types: logical

    Object Functions

    expand all

    insertInsert component or pipeline into existing pipeline
    parallelConnect components or pipelines in parallel to create pipeline
    replaceReplace existing pipeline component with new component
    seriesConnect components in series to create pipeline
    addAdd new component or pipeline to existing pipeline
    connectCreate connections between pipeline components
    disconnectRemove connections between ports in pipeline
    removeRemove existing components or pipelines from pipeline
    expandExpand subpipelines in pipeline
    learnInitialize and evaluate pipeline or component
    runExecute pipeline or component for inference after learning
    pruneRemove unnecessary components and dependencies from pipeline
    resetReset pipeline or component
    crossvalidateCross-validate pipeline
    viewView diagram of pipeline inputs, outputs, components, and connections
    describeDisplay summary of pipeline components
    packageCreate deployable archive or standalone application from pipeline

    Examples

    collapse all

    Create and explore a pipeline with two components.

    Create a component for removing missing data.

    removeMissing = observationRemoverComponent
    removeMissing = 
    
      observationRemoverComponent with properties:
    
                  Name: "ObservationRemover"
                Inputs: ["DataIn1"    "DataIn2"]
             InputTags: [1 2]
               Outputs: ["DataOut1"    "DataOut2"]
            OutputTags: [1 2]
    
       
    Structural Parameters (locked)
           NumDataFlow: 2
        ReferenceInput: 1
        FunctionHandle: @ismissing
    
       
    Run Parameters (unlocked)
            RunRemoval: 0
    
    
    Show all parameters

    removeMissing has two inputs and two outputs.

    Create a component for normalizing.

    normalizer = normalizerComponent
    normalizer = 
    
      normalizerComponent with properties:
    
                 Name: "Normalizer"
               Inputs: "DataIn"
            InputTags: 1
              Outputs: "DataScaled"
           OutputTags: 1
    
       
    Learnables (HasLearned = false)
                Scale: []
               Center: []
        UsedVariables: []
    
    
    Show all parameters

    The normalizer component has one input, one output, and three learnables: Scale, Center, and SelectedVariables. The learnable parameters have not been learned yet (the HasLearned property of the pipeline is false).

    Create a pipeline that contains the removeMissing and normalizer components. Use the series object function to create the pipeline automatically.

    pipeline = series(removeMissing,normalizer)
    pipeline = 
    
      LearningPipeline with properties:
    
                 Name: "defaultName"
               Inputs: ["DataIn1"    "DataIn2"]
            InputTags: [1 2]
              Outputs: ["DataScaled"    "DataOut2"]
           OutputTags: [1 2]
    
           Components: struct with 2 entries
          Connections: [5×2 table]
    
        HasLearnables: true
           HasLearned: false
    
    
    Show summary of the components

    Explore the Components property.

    pipeline.Components
    ans = 
    
      struct with fields:
    
        ObservationRemover: [1×1 observationRemoverComponent]
                Normalizer: [1×1 normalizerComponent]

    The Components property is a structure with one field per component. You can further index into the components to explore their properties. For example, you can enter pipeline.Components.ObservationRemover.

    Explore the pipeline connections.

    pipeline.Connections
    ans =
    
      5×2 table
    
                   Source                        Destination         
        _____________________________    ____________________________
    
        "DataIn1"                        "ObservationRemover/DataIn1"
        "DataIn2"                        "ObservationRemover/DataIn2"
        "ObservationRemover/DataOut1"    "Normalizer/DataIn"         
        "Normalizer/DataScaled"          "DataScaled"                
        "ObservationRemover/DataOut2"    "DataOut2"                 
    

    View the pipeline.

    view(pipeline)

    View pipeline

    Algorithms

    expand all

    Version History

    Introduced in R2026a

    See Also

    | |