Specify Indices for Training, Validation and Testing
26 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to evalutate a standard set of regression and classification problem as part of a team at work. My normal workflow is:
- Use the CVPARTITION function to automatically create training and validation dataset partitions.
- Train my model (e.g. via fitrensemble, fitcensemble, etc.)
- Use trained model on a "test" data sets to evalate predictability of the trained model.
This is hopefully a pretty standard use case and work flow. Here is my problem:
I want to be able manually specify the data partition indices for the "training" and "validation" data split myself. It's like using a holdout validation, except instead of letting Matlab randomly sample the indices, I would manually specify which points to use for training and which to use for validation. Unfortuantely I can't seem to figure out a way to just provide these partitions myself without having Matlab control the random sampling.
For perspective: when using a shallow neural network, we can do this by simply using the 'divideind' option and then providing the vector of indices for each split directly.
net.divideFcn = 'divideind';
net.divideParam.trainInd=trainIND;
net.divideParam.valInd=valInd;
net.divideParam.testInd=testInd;
This is somewhat important to my problem because I am working with a team of other scientists who use different software packages and approaches. For consistency and to allow comparison between models, we like to use the same data sets for training, validation and testing. However, I am not able to currently use the same validation splits in Matlab.
Am I missing a function or option in Matlab to do this? Any suggestions are welcome!
Thank you.
4 个评论
Poonpat Poonnoy
2020-5-19
Hi there,
I might have a solution which I used in my work.
First, i prepared the data for training (2000 datasets) , validating (500 datasets) and testing (500 datasets) in separated matrix. I noted the sizes each matrix as they are used to calculate the begining and end points of each groups.
Second, i concenated those matrix to a new matrix e.g. "p" which the number of column should be the summation of the samples in each group. Please beware of column data/row data type
Thrid, use [trainInd,valInd,testInd] = divideind(p,1:2000,2001:2500,2501:3000);
in this case the "train data" will be indexed from p matrix column 1 to 2000
"val data"will be indexed from p matrix column 2001 to 2500 and the rest is for the test.
I hope this help
Ross
2020-11-6
Seth, did you find a solution. My take on Poonpat's response is that yes it spits the data, but there does not seem to be a way to feed that into fitrensemble, obviously you can seperate off the validation dataset and use the genrated model.
回答(1 个)
Drew
2024-10-2
Custom partitions were introduced to cvpartition in R2023b. See https://www.mathworks.com/help/stats/cvpartition.html, and in particular the new cvpartition creation syntax 'c=cvpartition("CustomPartition",testSets)' . With this functionality, users can create cvparition objects that meet their partition requirements, such as for keeping certain observations grouped together because they come from the same underlying physical sample.
In addition, it is always possible to control the datasets completely by calling training, validation, and test functions explicitly with the desired data sets.
If this answer helps you, please remember to accept the answer.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gaussian Process Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!