This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: CompactRegressionEnsemble

Predict responses using ensemble of regression models


Yfit = predict(Mdl,X)
Yfit = predict(Mdl,X,Name,Value)


Yfit = predict(Mdl,X) returns predicted responses to the predictor data in the table or matrix X, based on the regression ensemble model Mdl.

Yfit = predict(Mdl,X,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

Input Arguments


Regression ensemble created by fitrensemble, or by the compact method.


Predictor data used to generate responses, specified as a numeric matrix or table.

Each row of X corresponds to one observation, and each column corresponds to one variable.

  • For a numeric matrix:

    • The variables making up the columns of X must have the same order as the predictor variables that trained Mdl.

    • If you trained Mdl using a table (for example, Tbl), then X can be a numeric matrix if Tbl contains all numeric predictor variables. To treat numeric predictors in Tbl as categorical during training, identify categorical predictors using the CategoricalPredictors name-value pair argument of fitrensemble. If Tbl contains heterogeneous predictor variables (for example, numeric and categorical data types) and X is a numeric matrix, then predict throws an error.

  • For a table:

    • predict does not support multi-column variables and cell arrays other than cell arrays of character vectors.

    • If you trained Mdl using a table (for example, Tbl), then all predictor variables in X must have the same variable names and data types as those that trained Mdl (stored in Mdl.PredictorNames). However, the column order of X does not need to correspond to the column order of Tbl. Tbl and X can contain additional variables (response variables, observation weights, etc.), but predict ignores them.

    • If you trained Mdl using a numeric matrix, then the predictor names in Mdl.PredictorNames and corresponding predictor variable names in X must be the same. To specify predictor names during training, see the PredictorNames name-value pair argument of fitrensemble. All predictor variables in X must be numeric vectors. X can contain additional variables (response variables, observation weights, etc.), but predict ignores them.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


Indices of weak learners in the ensemble ranging from 1 to NumTrained, where NumTrained is the number of weak learners.

Default: 1:NumTrained


A logical matrix of size N-by-NumTrained, where N is the number of observations in X, and NumTrained is the number of weak learners. When UseObsForLearner(I,J) is true, predict uses learner J in predicting observation I.

Default: true(N,NumTrained)

Output Arguments


A numeric column vector with the same number of rows as TBLdata or Xdata. Each row of Yfit gives the predicted response to the corresponding row of TBLdata or Xdata, based on the ens regression model.


expand all

Find the predicted mileage for a car based on regression ensemble trained on the carsmall data.

Load the carsmall data set and select the number of cylinders, engine displacement, horsepower, and vehicle weight as predictors.

load carsmall
X = [Cylinders Displacement Horsepower Weight];

Train an ensemble of regression trees and predict MPG for a four-cylinder car, with 200 cubic inch engine displacement, 150 horsepower, weighing 3000 lbs.

rens = fitrensemble(X,MPG);
Mileage = predict(rens,[4 200 150 3000])
Mileage = 25.6467

Extended Capabilities

Was this topic helpful?