RegressionPartitionedModel class

Cross-validated regression model

Description

RegressionPartitionedModel is a set of regression models trained on cross-validated folds. Estimate the quality of regression by cross validation using one or more "kfold" methods: kfoldPredict, kfoldLoss, and kfoldfun. Every "kfold" method uses models trained on in-fold observations to predict response for out-of-fold observations. For example, suppose you cross validate using five folds. In this case, every training fold contains roughly 4/5 of the data and every test fold contains roughly 1/5 of the data. The first model stored in Trained{1} was trained on X and Y with the first 1/5 excluded, the second model stored in Trained{2} was trained on X and Y with the second 1/5 excluded, and so on. When you call kfoldPredict, it computes predictions for the first 1/5 of the data using the first model, for the second 1/5 of data using the second model and so on. In short, response for every observation is computed by kfoldPredict using the model trained without this observation.

Construction

cvmodel = crossval(tree) creates a cross-validated classification model from a regression tree. For syntax details, see the crossval method reference page.

cvmodel = fitrtree(X,Y,Name,Value) creates a cross-validated model when name is one of 'CrossVal', 'KFold', 'Holdout', 'Leaveout', or 'CVPartition'. For syntax details, see the fitrtree function reference page.

Input Arguments

tree

A regression tree constructed with fitrtree.

Properties

CategoricalPredictors

List of categorical predictors. CategoricalPredictors is a numeric vector with indices from 1 to p, where p is the number of columns of X.

CrossValidatedModel

Name of the cross-validated model, a string.

Kfold

Number of folds used in a cross-validated tree, a positive integer.

ModelParameters

Object holding parameters of tree.

Partition

The partition of class cvpartition used in the cross-validated model.

PredictorNames

A cell array of names for the predictor variables, in the order in which they appear in X.

ResponseName

Name of the response variable Y, a string.

ResponseTransform

Function handle for transforming the raw response values (mean squared error). The function handle should accept a matrix of response values and return a matrix of the same size. The default string 'none' means @(x)x, or no transformation.

Add or change a ResponseTransform function using dot notation:

ctree.ResponseTransform = @function

Trained

The trained learners, a cell array of compact regression models.

W

The scaled weights, a vector with length n, the number of rows in X.

X

A matrix of predictor values. Each column of X represents one variable, and each row represents one observation.

Y

A numeric column vector with the same number of rows as X. Each entry in Y is the response to the data in the corresponding row of X.

Methods

kfoldfunCross validate function
kfoldLossCross-validation loss of partitioned regression model
kfoldPredictPredict response for observations not used for training.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Examples

expand all

Evaluate Cross-Validation Error

Load the sample data. Create a variable X containing the Horsepower and Weight data.

load carsmall
X = [Horsepower Weight];

Construct a regression tree using the sample data.

tree = fitrtree(X,MPG);

Evaluate the cross-validation error of the carsmall data using Horsepower and Weight as predictor variables for mileage (MPG).

L = kfoldLoss(cvtree)
L =

   26.4414
Was this topic helpful?