Skip to Main Content Skip to Search
Product Documentation

kfoldLoss - Class: ClassificationPartitionedEnsemble

Classification loss for observations not used for training

Syntax

L = kfoldLoss(ens)
L = kfoldLoss(ens,Name,Value)

Description

L = kfoldLoss(ens) returns loss obtained by cross-validated classification model ens. For every fold, this method computes classification loss for in-fold observations using a model trained on out-of-fold observations.

L = kfoldLoss(ens,Name,Value) calculates 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.

Input Arguments

ens

Object of class ClassificationPartitionedEnsemble. Create ens with fitensemble along with one of the cross-validation options: 'crossval', 'kfold', 'holdout', 'leaveout', or 'cvpartition'. Alternatively, create ens from a classification ensemble with crossval.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments, where 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.

'folds'

Indices of folds ranging from 1 to ens.KFold. Use only these folds for predictions.

Default: 1:ens.KFold

'lossfun '

Function handle or string representing a loss function. Built-in loss functions:

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

Default: 'classiferror'

'mode'

A string for determining the output of kfoldLoss:

  • 'average'L is a scalar, the loss averaged over all folds.

  • 'individual'L is a vector of length ens.KFold, where each entry is the loss for a fold.

  • 'cumulative'L is a vector in which element J is obtained by using learners 1:J from the input list of learners.

Default: 'average'

Output Arguments

L

Loss, by default the fraction of misclassified data. L can be a vector, and can mean different things, depending on the name-value pair settings.

Definitions

Loss Functions

The built-in loss functions are:

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

function loss = lossfun(C,S,W,COST)

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

Examples

Find the average cross-validated classification error for an ensemble model of the ionosphere data:

load ionosphere
ens = fitensemble(X,Y,'AdaBoostM1',100,'Tree');
cvens = crossval(ens);
L = kfoldLoss(cvens)

L =
    0.0826

See Also

crossval | kfoldEdge | kfoldfun | kfoldMargin | kfoldPredict

How To

  


 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS