predict - Predict responses using regression tree model - MATLAB (original) (raw)

Predict responses using regression tree model

Syntax

Description

[Yfit](#bst08n4-1-Yfit) = predict([tree](#bst08n4-1%5Fsep%5Fshared-tree),[X](#mw%5F94577590-8ed5-497b-ab08-5b2359b3dded)) returns a vector of predicted responses for the predictor data in the table or matrix X, based on the trained regression treetree.

example

[Yfit](#bst08n4-1-Yfit) = predict([tree](#bst08n4-1%5Fsep%5Fshared-tree),[X](#mw%5F94577590-8ed5-497b-ab08-5b2359b3dded),Subtrees=[subtrees](#mw%5F58ee4b0c-e622-4f31-8c86-c089f44eb064)) also prunes tree to the level specified bysubtrees, before predicting responses.

[[Yfit](#bst08n4-1-Yfit),[node](#bst08n4-1-node)] = predict(___) also returns a vector of predicted node numbers for the responses, using any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Load the carsmall data set. Consider Displacement, Horsepower, and Weight as predictors of the response MPG.

load carsmall X = [Displacement Horsepower Weight];

Grow a regression tree using the entire data set.

Predict the MPG for a car with 200 cubic inch engine displacement, 150 horsepower, and that weighs 3000 lbs.

X0 = [200 150 3000]; MPG0 = predict(Mdl,X0)

The regression tree predicts the car's efficiency to be 21.94 mpg.

Input Arguments

collapse all

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.

For a numeric matrix:

For a table:

Data Types: single | double | table

Pruning level, specified as a vector of nonnegative integers in ascending order or "all".

If you specify a vector, then all elements must be at least0 and at most max(tree.PruneList).0 indicates the full, unpruned tree, andmax(tree.PruneList) indicates the completely pruned tree (that is, just the root node).

If you specify "all", thenpredict operates on all subtrees (that is, the entire pruning sequence). This specification is equivalent to using0:max(tree.PruneList).

predict prunes tree to each level specified by subtrees, and then estimates the corresponding output arguments. The size of subtrees determines the size of some output arguments.

For the function to invoke subtrees, the propertiesPruneList and PruneAlpha oftree must be nonempty. In other words, growtree by setting Prune="on" when you use fitrtree, or by pruning tree using prune.

Data Types: single | double | char | string

Output Arguments

collapse all

Predicted response values, returned as a numeric column vector with the same number of rows as X. Each row ofYfit gives the predicted response to the corresponding row of X, based on the regression modeltree.

Node numbers for the predictions, returned as a numeric vector. Each entry corresponds to the predicted leaf node in tree for the corresponding row of X.

Alternative Functionality

To integrate the prediction of a regression tree model into Simulink®, you can use the RegressionTree Predict block in the Statistics and Machine Learning Toolbox™ library or a MATLAB® Function block with the predict function. For examples, see Predict Responses Using RegressionTree Predict Block and Predict Class Labels Using MATLAB Function Block.

When deciding which approach to use, consider the following:

Extended Capabilities

expand all

This function fully supports tall arrays. You can use models trained on either in-memory or tall data with this function.

For more information, see Tall Arrays.

Usage notes and limitations:

For more information, see Introduction to Code Generation.

Usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2011a