Does cvpartition work with structs?

3 次查看(过去 30 天)
I am trying to work with a dataset provided to me that is a struct. I want to use cvpartition() as to maintain the ratio of classes in the resulting train and test sets, otherwise I would use randperm(). Here is the code I am trying to run:
% Struct is Messages
% "label" is the field containing the classes I want to sort by
c = cvpartition(Messages.label,'Holdout',1/3);
testIndices=test(c);
trainIndices=training(c);
trainData=data(trainIndices,:);
testData=data(testIndices,:);
The following is the error I receive upon running:
Error using internal.stats.cvpartitionInMemoryImpl (line 71)
CVPARTITION can have at most two optional arguments
Error in cvpartition (line 175)
cv.Impl = internal.stats.cvpartitionInMemoryImpl(varargin{:});
Error in scratch_script (line 8)
c = cvpartition(Messages.label,'Holdout',1/3);
Any guidance here would be appreciated. Thanks in advance!

采纳的回答

Walter Roberson
Walter Roberson 2021-11-18
c = cvpartition({Messages.label}, 'Holdout', 1/3);
  2 个评论
Brandon Carrier
Brandon Carrier 2021-11-18
Thank you for the quick response! I tried implementing which got me past that error, but threw another. I'd appreciate any other guidance you may have.
Error using statslib.internal.grp2idx (line 99)
Grouping variable must be a categorical, numeric, logical, datetime or duration vector, character array, string array, or cell vector of character vectors.
Error in grp2idx (line 28)
[varargout{1:nargout}] = statslib.internal.grp2idx(s);
Error in internal.stats.cvpartitionInMemoryImpl (line 136)
cv.Group = grp2idx(N);
Error in cvpartition (line 175)
cv.Impl = internal.stats.cvpartitionInMemoryImpl(varargin{:});
Error in scratch_script (line 9)
c = cvpartition({Messages.label}, 'Holdout', 1/3 );
For reference, the contents of the field is just 1's and 0's.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Regression 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by