resubLoss

Class: RegressionTree

Regression error by resubstitution

Syntax

L = resubLoss(tree)
L = resubLoss(tree,Name,Value)
L = resubLoss(tree,'Subtrees',subtreevector)
[L,se] = resubLoss(tree,'Subtrees',subtreevector)
[L,se,NLeaf] = resubLoss(tree,'Subtrees',subtreevector)
[L,se,NLeaf,bestlevel] = resubLoss(tree,'Subtrees',subtreevector)
[L,...] = resubLoss(tree,'Subtrees',subtreevector,Name,Value)

Description

L = resubLoss(tree) returns the resubstitution loss, meaning the loss computed for the data that fitrtree used to create tree.

L = resubLoss(tree,Name,Value) returns the loss with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.

L = resubLoss(tree,'Subtrees',subtreevector) returns a vector of mean squared errors for the trees in the pruning sequence subtreevector.

[L,se] = resubLoss(tree,'Subtrees',subtreevector) returns the vector of standard errors of the classification errors.

[L,se,NLeaf] = resubLoss(tree,'Subtrees',subtreevector) returns the vector of numbers of leaf nodes in the trees of the pruning sequence.

[L,se,NLeaf,bestlevel] = resubLoss(tree,'Subtrees',subtreevector) returns the best pruning level as defined in the TreeSize name-value pair. By default, bestlevel is the pruning level that gives loss within one standard deviation of minimal loss.

[L,...] = resubLoss(tree,'Subtrees',subtreevector,Name,Value) returns loss statistics with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.

Input Arguments

tree

A regression tree constructed using fitrtree.

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.

'LossFun'

Function handle, or the string 'mse' meaning mean squared error.

You can write your own loss function in the syntax described in Loss Functions.

Default: 'mse'

Name,Value arguments associated with pruning subtrees:

'Subtrees'

A vector with integer values from 0 (full unpruned tree) to the maximal pruning level max(tree.PruneList).

Default: 0

'TreeSize'

One of the following strings:

  • 'se'loss returns the highest pruning level with loss within one standard deviation of the minimum (L + se, where L and se relate to the smallest value in Subtrees).

  • 'min'loss returns the element of Subtrees with smallest loss, usually the smallest element of Subtrees.

Output Arguments

L

Mean squared error, a vector the length of Subtrees. The meaning of the error depends on the values in Weights and LossFun.

se

Standard error of loss, a vector the length of Subtrees.

NLeaf

Number of leaves (terminal nodes) in the pruned subtrees, a vector the length of Subtrees.

bestlevel

A scalar whose value depends on TreeSize:

  • TreeSize = 'se'loss returns the highest pruning level with loss within one standard deviation of the minimum (L + se, where L and se relate to the smallest value in Subtrees).

  • TreeSize = 'min'loss returns the element of Subtrees with smallest loss, usually the smallest element of Subtrees.

Definitions

Loss Functions

The built-in loss function is 'mse', meaning mean squared error.

To write your own loss function, create a function file of the form

function loss = lossfun(Y,Yfit,W)
  • N is the number of rows of tree.X.

  • Y is an N-element vector representing the observed response.

  • Yfit is an N-element vector representing the predicted responses.

  • W is an N-element vector representing the observation weights.

  • The output loss should be a scalar.

Pass the function handle @lossfun as the value of the LossFun name-value pair.

Examples

Find the mean square error of a model of the carsmall data:

load carsmall
X = [Displacement Horsepower Weight];
tree = fitrtree(X,MPG);
resubLoss(tree)

ans =
    4.8952
Was this topic helpful?