主要内容

learn

Initialize and evaluate pipeline or component

Since R2026a

    Description

    learnedPipe = learn(pipe,input1,...,inputN) evaluates all the nodes in the pipeline or component pipe by passing the inputs through pipe in the specified order. The function learns, or initializes, any data-dependent parameters (learnables) in the components of pipe. For components in pipe without data-dependent parameters, or for components already learned, using learn is equivalent to using the run object function.

    You can use the returned pipeline or component learnedPipe for inference with new data by using run.

    example

    [learnedPipe,output1,...,outputM] = learn(pipe,input1,...,inputN) returns additional outputs corresponding to the pipeline or component outputs in the Outputs property. You can see the identity and order of the outputs using pipe.Outputs.

    example

    ___ = learn(___,Name,Value) specifies optional learn parameters in addition to any of the input or output argument combinations in previous syntaxes. The software forwards the learn parameter values to individual components during the execution of pipe.

    • If pipe is a LearningPipeline object, then specify Name as the component name with / as a prefix to the parameter name, to disambiguate between components that have the same parameter name. For example, specify learn(pipe,X,Y,"ClassificationSVM/Standardize",true).

    • If pipe is a learning component object, then specify Name as the parameter name. In this case, you can use the Name=Value syntax. For example, specify learn(pipe,X,Y,Standardize=true). Use help(pipe) to see the available learn parameters.

    Examples

    collapse all

    Create a pipeline with two components: one that performs principal component analysis and retains three components, and one that performs ECOC classification.

    pca = pcaComponent(NumComponents=3);
    ecoc = classificationECOCComponent;
    pipeline = series(pca,ecoc);
    

    Load sample data and define the predictor and response variables. Then learn the pipeline parameters.

    fisheriris = readtable("fisheriris.csv");
    X = fisheriris(:,1:end-1);
    Y = fisheriris(:,end);
    learnedPipeline = learn(pipeline,X,Y);
    

    You can ask for additional outputs in the order specified by the pipeline Outputs property. Compute the resubstitution predictions, classification scores, and loss value.

    [learnedPipeline,resubpredict,scores,resubloss] = ...
        learn(pipeline,X,Y);

    Initiate a pipeline that performs principal component analysis and classification using SVM. Prepare the pipeline for using observation weights. Confirm that observation weights form one of the inputs to the pipeline.

    pcaWeights = pcaComponent(NumComponents=3,UseWeights=true);
    svmWeights = classificationSVMComponent(UseWeights=true);
    pipeline = series(pcaWeights,svmWeights);
    inputs = pipeline.Inputs
    inputs = 
    
      1×3 string array
    
        "DataIn"    "Response"    "ObservationWeights"

    ObservationWeights is one of the inputs required by the pipeline.

    Load sample data. Define the predictor variables, response variable, and observation weights.

    fisheriris = readtable("fisheriris.csv");
    X = fisheriris(1:100,1:end-1);
    Y = fisheriris(1:100,end);
    W = table(rand(size(Y)));

    Learn the pipeline parameters. You must provide the inputs in the order in which they appear in the Inputs property.

    learnedPipeline = learn(pipeline,X,Y,W);

    Input Arguments

    collapse all

    Pipeline or component to evaluate, specified as a LearningPipeline object or a learning component object in one of the following tables.

    Data Preprocessing Components

    ComponentPurpose
    equalWidthBinnerComponentGrouping data into equal-width bins
    frequencyEncoderComponentFrequency encoding categorical variables
    kmeansEncoderComponentFeature extraction using k-means clustering
    normalizerComponentNormalizing data
    observationImputerComponentImputing missing values
    observationRemoverComponentRemoving observations
    oneHotEncoderComponentEncoding categorical data into one-hot vectors
    outlierImputerComponentImputing outlier values
    outlierRemoverComponentRemoving outlier values
    pcaComponentPrincipal component analysis (PCA)
    quantileBinnerComponentBinning data into equally probable bins
    ricaComponentFeature extraction using reconstruction independent component analysis (RICA)
    sparseFilterComponentFeature extraction using sparse filtering

    Feature Selection and Engineering Components

    ComponentPurpose
    featureSelectionClassificationANOVAComponentFeature selection using one-way ANOVA test
    featureSelectionClassificationChi2ComponentFeature selection using chi-square tests
    featureSelectionClassificationKruskalWallisComponentFeature selection using Kruskal-Wallis test
    featureSelectionClassificationMRMRComponentMinimum redundancy maximum relevance (MRMR) feature selection in classification workflow
    featureSelectionClassificationNCAComponentNeighborhood component analysis (NCA) feature selection in classification workflow
    featureSelectionClassificationReliefFComponentReliefF feature selection in classification workflow
    featureSelectionRegressionFTestComponentFeature selection using F-tests
    featureSelectionRegressionMRMRComponentMinimum redundancy maximum relevance (MRMR) feature selection in regression workflow
    featureSelectionRegressionNCAComponentNeighborhood component analysis (NCA) feature selection in regression workflow
    featureSelectionRegressionReliefFComponentReliefF feature selection in regression workflow
    variableSelectorComponentManual variable selection

    Classification Model Components

    ComponentPurpose
    classificationDiscriminantComponentDiscriminant analysis classification
    classificationECOCComponentMulticlass classification using error-correcting output codes (ECOC) model
    classificationEnsembleComponentEnsemble classification
    classificationGAMComponentBinary classification using generalized additive model (GAM)
    classificationKernelComponentClassification using Gaussian kernel with random feature expansion
    classificationKNNComponentClassification using k-nearest neighbor model
    classificationLinearComponentBinary classification of high-dimensional data using a linear model
    classificationNaiveBayesComponentMulticlass classification using a naive Bayes model
    classificationNeuralNetworkComponentClassification using a neural network model
    classificationSVMComponentOne-class and binary classification using a support vector machine (SVM) classifier
    classificationTreeComponentDecision tree classifier

    Regression Model Components

    ComponentPurpose
    regressionEnsembleComponentEnsemble regression
    regressionGAMComponentRegression using generalized additive model (GAM)
    regressionGPComponentGaussian process regression
    regressionKernelComponentKernel regression using explicit feature expansion
    regressionLinearComponentLinear regression
    regressionNeuralNetworkComponentNeural network regression
    regressionSVMComponentRegression using a support vector machine (SVM)
    regressionTreeComponentDecision tree regression

    Custom Components

    ComponentPurpose
    functionComponentCustom function

    Input data required by the pipeline or component pipe, specified as a table. Input data can be predictor data, response values, observation weights, and so on. The order of the inputs 1, …, N must match the order of the pipeline or component inputs, as listed in the Inputs property. You can see the identity and order of the inputs using pipe.Inputs.

    Data Types: table

    Output Arguments

    collapse all

    Pipeline or component evaluated using the inputs, returned as a LearningPipeline or learning component object. A learned pipeline or component can subsequently run using the learned or initialized parameters.

    Output data computed by the component based on the input data, returned as separate variables.

    Version History

    Introduced in R2026a