predict
Description
Examples
Import a pretrained XGBoost regression model trained using the carsmall dataset to predict the fuel economy (MPG) of a car. The pretrained model is provided with this example and was trained in Python using Cylinders, Displacement, Horsepower, and Weight as predictors.
load carsmall modelfile = "trainedRegressionXGBoostModel.json"; Mdl = importModelFromXGBoost(modelfile)
Mdl =
CompactRegressionXGBoost
ResponseName: 'Y'
ResponseTransform: 'none'
NumTrained: 30
ImportedModelParameters: [1×1 struct]
Properties, Methods
Predict the MPG for a car with 4 cylinders, 200 cubic inch engine displacement, 150 horsepower, and that weighs 3000 lbs.
X0 = [4 200 150 3000]; predict(Mdl,X0)
ans = single
24.0842
The XGBoost model predicts the car's efficiency to be 24.08 mpg.
Input Arguments
Compact regression XGBoost model, specified as a CompactRegressionXGBoost model object created with importModelFromXGBoost.
Predictor data used to predict responses, specified as a numeric matrix or a table.
Each row of X corresponds to one observation, and each column
corresponds to one variable. If there are missing values in a row, the software uses the
learned branch direction from the pretrained model. The predictor data cannot include
categorical predictors (logical, categorical,
char, string, or cell).
For a numeric matrix, the variables that make up the columns of
X must have the same order as the predictor variables used to
train mdl.
For a table:
predictdoes not support multicolumn variables or cell arrays other than cell arrays of character vectors.All predictor variables in
Xmust have the same variable names and data types as those stored inmdl.PredictorNames.Xcan contain additional variables, such as response variables and observation weights, butpredictignores them.
Flag to run in parallel, specified as a numeric or logical
1 (true) or 0
(false). If you specify UseParallel=true, the
predict function executes for-loop iterations by
using parfor. The loop runs in parallel when you
have Parallel Computing Toolbox™.
Example: UseParallel=true
Data Types: logical
Output Arguments
Extended Capabilities
Usage notes and limitations:
You cannot use the
UseParallelname-value argument with tall arrays.
For more information, see Tall Arrays.
Usage notes and limitations:
Use
saveLearnerForCoder,loadLearnerForCoder, andcodegen(MATLAB Coder) to generate code for thepredictfunction. Save a trained model by usingsaveLearnerForCoder. Define an entry-point function that loads the saved model by usingloadLearnerForCoderand calls thepredictfunction. Then usecodegento generate code for the entry-point function.Only single-precision C/C++ code is supported.
Fixed-point code generation is not supported.
This table contains notes about the arguments of
predict. Arguments not included in this table are fully supported.Argument Notes and Limitations XFor general code generation,
Xmust be a single-precision matrix.The number of rows, or observations, in
Xcan be a variable size, but the number of columns inXmust be fixed.
For more information, see Introduction to Code Generation for Statistics and Machine Learning Functions.
To run in parallel, set the UseParallel name-value argument to
true in the call to this function.
For more general information about parallel computing, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).
You cannot use UseParallel with tall or GPU arrays or in code generation.
Usage notes and limitations:
You cannot use
UseParallelwith GPU arrays.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2026a
See Also
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.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- 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)