Main Content

training

Training indices for cross-validation

Description

example

idx= training(c)returns the training indicesidxfor acvpartitionobjectcof type'holdout''resubstitution'.

  • Ifc.Typeis'holdout', thenidxspecifies the observations in the training set.

  • Ifc.Typeis'resubstitution', thenidxspecifies all observations.

example

idx= training(c,i)returns the training indices for repetitioniof acvpartitionobjectcof type'kfold''leaveout'.

  • Ifc.Typeis'kfold', thenidxspecifies the observations in theith training set.

  • Ifc.Typeis'leaveout', thenidxspecifies the observations reserved for training at repetitioni.

Examples

collapse all

Identify the observations that are in the training set of acvpartitionobject for holdout validation.

分区10观察s for holdout validation. Select approximately 30% of the observations to be in the test (holdout) set.

rng('default')% For reproducibilityc = cvpartition(10,'Holdout',0.30)
c = Hold-out cross validation partition NumObservations: 10 NumTestSets: 1 TrainSize: 7 TestSize: 3

Identify the training set observations. Observations that correspond to 1s are in the training set.

set = training(c)
set =10x1 logical array1 1 1 0 1 1 1 1 0 0

Visualize the results. All observations except the fourth, ninth, and tenth are in the training set.

h = heatmap(double(set),'ColorbarVisible','off'); sorty(h,'1','ascend') ylabel('Observation') title('Training Set Observations')

Figure contains an object of type heatmap. The chart of type heatmap has title Training Set Observations.

Identify the observations that are in the training sets of acvpartitionobject for 3-fold cross-validation.

分区10观察s for 3-fold cross-validation. Notice thatccontains three repetitions of training and test data.

rng('default')% For reproducibilityc = cvpartition(10,'KFold',3)
c = K-fold cross validation partition NumObservations: 10 NumTestSets: 3 TrainSize: 7 6 7 TestSize: 3 4 3

Identify the training set observations for each repetition of training and test data. Observations that correspond to 1s are in the corresponding training set.

set1 = training(c,1)
set1 =10x1 logical array0 0 1 1 1 1 1 1 0 1
set2 = training(c,2); set3 = training(c,3);

Visualize the results. All observations except the first, second, and ninth are in the first training set. All observations except the third, sixth, eighth, and tenth are in the second training set. All observations except the fourth, fifth, and seventh are in the third training set.

data = [set1,set2,set3]; h = heatmap(double(data),'ColorbarVisible','off'); sorty(h,{'1','2','3'},'ascend')包含('Repetition') ylabel('Observation') title('Training Set Observations')

Figure contains an object of type heatmap. The chart of type heatmap has title Training Set Observations.

Input Arguments

collapse all

Validation partition, specified as acvpartitionobject. The validation partition type ofc,c.Type, is'kfold','holdout','leaveout', or'resubstitution'.

Repetition index, specified as a positive integer scalar. Specifyingi在dicates to find the observations in theith training set.

Data Types:single|double

Output Arguments

collapse all

Indices for training set observations, returned as a logical vector. A value of 1 indicates that the corresponding observation is in the training set. A value of 0 indicates that the corresponding observation is in the test set.

Version History

Introduced in R2008a

See Also

|