Training indices for cross-validation - MATLAB training - MathWorks India (2024)

Training indices for cross-validation

collapse all in page

Syntax

idx = training(c)

idx = training(c,i)

idx = training(c,"all")

Description

example

idx = training(c) returns the training indices idx for a cvpartition object c of type 'holdout' or 'resubstitution'.

  • If c.Type is 'holdout', then idx specifies the observations in the training set.

  • If c.Type is 'resubstitution', then idx specifies all observations.

idx = training(c,i) returns the training indices for the repetitions specified in i of a cvpartition object c of type 'kfold' or 'leaveout'.

  • If c.Type is 'kfold', then idx(:,j) specifies the observations in training set i(j).

  • If c.Type is 'leaveout', then idx(:,j) specifies the observations reserved for training at repetition i(j).

example

idx = training(c,"all") returns the training indices for all repetitions of a cvpartition object c. Column j in idx indicates the observations in training set j for an object of type 'kfold' or 'leaveout'. (since R2023b)

Examples

collapse all

Identify Training Indices in Holdout Partition

Open Live Script

Identify the observations that are in the training set of a cvpartition object for holdout validation.

Partition 10 observations 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 IsCustom: 0

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

set = training(c)
set = 10x1 logical array 1 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')

Training indices for cross-validation - MATLAB training- MathWorks India (1)

Identify Training Indices in k-Fold Partition

Open Live Script

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

Partition 10 observations for 3-fold cross-validation. Notice that c contains 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 IsCustom: 0

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

data = training(c,"all")
data = 10x3 logical array 0 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 0 1 0 1 1 1 0 1

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.

h = heatmap(double(data),"ColorbarVisible","off");sorty(h,["1","2","3"],"ascend")xlabel("Repetition")ylabel("Observation")title("Training Set Observations")

Training indices for cross-validation - MATLAB training- MathWorks India (2)

Input Arguments

collapse all

cValidation partition
cvpartition object

Validation partition, specified as a cvpartition object. The validation partition type of c, c.Type, is 'kfold', 'holdout', 'leaveout', or 'resubstitution'.

iRepetition indices
positive integer vector

Repetition indices, specified as a positive integer vector. For each element in i, the software finds the observations in the training set of the corresponding repetition.

Example: 2

Example: [1 3 5]

Data Types: single | double

Output Arguments

collapse all

idx — Indices for training set observations
logical matrix

Indices for training set observations, returned as a logical matrix. Each row corresponds to an observation, and each column corresponds to a repetition.

A value of 1 (true) indicates that the corresponding observation is in the training set. A value of 0 (false) indicates that the corresponding observation is in the test set.

Version History

Introduced in R2008a

expand all

See Also

cvpartition | test

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Training indices for cross-validation - MATLAB training- MathWorks India (3)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Training indices for cross-validation - MATLAB training
- MathWorks India (2024)
Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 6544

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.