predict
R2026bPredict responses for new observations from neural network incremental learning model
Since R2026b
Syntax
Description
Examples
Create an incremental learning model by converting a traditionally trained neural network model, and predict class labels using both models.
Load the human activity data set.
load humanactivityFor details on the data set, enter Description at the command line.
Fit a neural network classification model to the entire data set.
Mdl = fitcnet(feat,actid);
Mdl is a ClassificationNeuralNetwork model object representing a traditionally trained neural network classification model.
Convert the traditionally trained neural network classification model to a model for incremental learning.
IncrementalMdl = incrementalLearner(Mdl)
IncrementalMdl =
incrementalClassificationNeuralNetwork
IsWarm: 0
Metrics: [1×2 table]
ClassNames: [1 2 3 4 5]
ScoreTransform: 'none'
LayerSizes: 10
Activations: "relu"
OutputLayerActivation: "softmax"
Solver: "minibatch-lbfgs"
Properties, Methods
IncrementalMdl is an incrementalClassificationNeuralNetwork model object prepared for incremental learning.
The incrementalLearner function initializes the incremental learner by passing the neural network and model parameters to it, along with other information Mdl extracts from the training data. An incremental learner created from converting a traditionally trained model can generate predictions without further processing.
Predict class labels for all observations using both models.
ttlabels = predict(Mdl,feat); illabels = predict(IncrementalMdl,feat); isequal(ttlabels,illabels)
ans = logical
1
Both models predict the same labels for each observation.
Create an incremental learning model by converting a traditionally trained neural network model, and predict responses using both models.
Load the 2015 NYC housing data set. For more details on the data, see NYC Open Data.
load NYCHousing2015Extract the response variable SALEPRICE from the table. For numerical stability, scale SALEPRICE by 1e6.
Y = NYCHousing2015.SALEPRICE/1e6; NYCHousing2015.SALEPRICE = [];
To reduce computational cost for this example, remove the NEIGHBORHOOD column, which contains a categorical variable with 254 categories.
NYCHousing2015.NEIGHBORHOOD = [];
Create dummy variable matrices from the other categorical predictors.
catvars = ["BOROUGH","BUILDINGCLASSCATEGORY"]; dumvarstbl = varfun(@(x)dummyvar(categorical(x)),NYCHousing2015, ... InputVariables=catvars); dumvarmat = table2array(dumvarstbl); NYCHousing2015(:,catvars) = [];
Treat all other numeric variables in the table as predictors of sales price. Concatenate the matrix of dummy variables to the rest of the predictor data.
idxnum = varfun(@isnumeric,NYCHousing2015,OutputFormat="uniform");
X = [dumvarmat NYCHousing2015{:,idxnum}];Fit a neural network regression model to the entire data set. Standardize the predictor data.
Mdl = fitrnet(X,Y,Standardize=true)
Mdl =
RegressionNeuralNetwork
ResponseName: 'Y'
CategoricalPredictors: []
ResponseTransform: 'none'
NumObservations: 91446
LayerSizes: 10
Activations: 'relu'
OutputLayerActivation: 'none'
Solver: 'LBFGS'
ConvergenceInfo: [1×1 struct]
TrainingHistory: [1000×7 table]
Properties, Methods
Mdl is a RegressionNeuralNetwork model object representing a traditionally trained neural network regression model.
Convert the traditionally trained neural network regression model to a model for incremental learning. Use the FreeREX solver.
IncrementalMdl = incrementalLearner(Mdl,TrainingOptions=incrementalTrainingOptions("freerex"))IncrementalMdl =
incrementalRegressionNeuralNetwork
IsWarm: 1
Metrics: [1×2 table]
ResponseTransform: 'none'
LayerSizes: 10
Activations: "relu"
OutputLayerActivation: "none"
Solver: "freerex"
Properties, Methods
IncrementalMdl is an incrementalRegressionNeuralNetwork model object prepared for incremental learning.
The incrementalLearner function initializes the incremental learner by passing model parameters to it, along with other information Mdl extracted from the training data. IncrementalMdl is warm (IsWarm is 1), which means that incremental learning functions can start tracking performance metrics.
An incremental learner created from converting a traditionally trained model can generate predictions without further processing.
Predict sales prices for all observations using both models.
ttyfit = predict(Mdl,X); ilyfit = predict(IncrementalMdl,X); compareyfit = norm(ttyfit - ilyfit)
compareyfit = 0
The difference between the fitted values generated by the models is 0.
Input Arguments
Incremental learning model, specified as an incrementalClassificationNeuralNetwork or incrementalRegressionNeuralNetwork model object. You can create
Mdl directly or by converting a supported, traditionally trained
machine learning model using the incrementalLearner function. For
more details, see the corresponding reference page.
To generate predictions, the model must be trained. That is, you must pass
Mdl and data to fit or
updateMetricsAndFit before calling predict, or
convert a traditionally trained model using
incrementalLearner.
Chunk of predictor data, specified as a floating-point matrix of
n observations and Mdl.NumPredictors predictor
variables. The value of the
ObservationsIn name-value argument determines the orientation
of the variables and observations. The default ObservationsIn
value is "rows", which indicates that observations in the predictor
data are oriented along the rows of X.
The length of the observation responses (labels) Y and the
number of observations in X must be equal;
Y( is the response (label) of
observation j (row or column) in j)X.
Note
predictsupports only floating-point input predictor data. If your input data includes categorical data, you must prepare an encoded version of the categorical data. Usedummyvarto convert each categorical variable to a numeric matrix of dummy variables. Then, concatenate all dummy variable matrices and any other numeric predictors. For more details, see Dummy Variables.
Data Types: single | double
Predictor data observation dimension, specified as "rows" or
"columns".
Example: ObservationsIn="columns"
Data Types: char | string
Output Arguments
Predicted responses (labels), returned as a categorical or character array;
floating-point, logical, or string vector; or cell array of character vectors with
n rows. n is the number of observations in
X, and label( is
the predicted response for observation
j).j
For regression problems,
Labelis a floating-point vector.For classification problems,
Labelhas the same data type as the class names stored inMdl.ClassNames. (The software treats string arrays as cell arrays of character vectors.)The
predictfunction assigns the observation to the class that yields the largest classification score (posterior probability). If the neural network uses the softmax output layer activation (default), scores represent posterior class probabilities.
Classification scores, returned as an n-by-K
numeric matrix when Mdl is an
incrementalClassificationNeuralNetwork model. n is
the number of observations in X and K is the
number of classes (numel(Mdl.ClassNames)).
Score(
is the classification score of observation
j,k) being classified into class
j. The class order corresponds to
kMdl.ClassNames.
If the output layer activation is "softmax" (default for
classification), the scores are posterior class probabilities. That is, for each
observation, the scores across all classes sum to 1.
Algorithms
To predict a class label for a new observation, predict
propagates the observation through the fully connected layers of the neural network. Each
layer applies a linear transformation (weights and biases) followed by an activation
function. The final output layer applies the softmax activation function to produce
posterior class probabilities. The predicted class is the one with the highest posterior
probability.
If the predictor means (Mdl.Mu) and standard deviations
(Mdl.Sigma) are not empty, predict
standardizes the predictor data before propagating it through the network.
Version History
Introduced in R2026b
See Also
Objects
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)