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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)