matlab 分层交叉验证分区错误 "CVPARTITION can have at most one optional argument"
Error in matlab stratified cross validation partitioning "CVPARTITION can have at most one optional argument"
我正在尝试执行分层交叉验证,因为数据非常不平衡。数据的输出标签在矩阵 predictionMatrix
中。它是一个 832*1 维矩阵,值为 0/1。对于交叉验证,我使用函数 cvpartition
,但它生成错误:
CVPARTITION can have at most one optional argument
密码是:
c = cvpartition(predictionMatrix,'KFold',5,'Stratify',true);
您使用的一定是旧版本的 MATLAB。例如,在 MATLAB 版本 R2016a 中,cvpartition
命令仅采用一对可选参数,如
c = cvpartition(predictionMatrix,'KFold',5)
并且选项 ...'Stratify',true
根本不可用。所以你会得到和你一样的错误:
I = randi(100,832,1);
predictionMatrix = (I>50);
c = cvpartition(predictionMatrix,'KFold',5,'Stratify',true);
Error using cvpartition (line 130)
CVPARTITION can have at most one optional argument
但是,在 MATLAB 版本 R2018a 及更高版本中,相同的代码可以正常工作:
I = randi(100,832,1);
predictionMatrix = (I>50);
c = cvpartition(predictionMatrix,'KFold',5,'Stratify',true)
c =
K-fold cross validation partition
NumObservations: 832
NumTestSets: 5
TrainSize: 666 665 665 666 666
TestSize: 166 167 167 166 166
我正在尝试执行分层交叉验证,因为数据非常不平衡。数据的输出标签在矩阵 predictionMatrix
中。它是一个 832*1 维矩阵,值为 0/1。对于交叉验证,我使用函数 cvpartition
,但它生成错误:
CVPARTITION can have at most one optional argument
密码是:
c = cvpartition(predictionMatrix,'KFold',5,'Stratify',true);
您使用的一定是旧版本的 MATLAB。例如,在 MATLAB 版本 R2016a 中,cvpartition
命令仅采用一对可选参数,如
c = cvpartition(predictionMatrix,'KFold',5)
并且选项 ...'Stratify',true
根本不可用。所以你会得到和你一样的错误:
I = randi(100,832,1);
predictionMatrix = (I>50);
c = cvpartition(predictionMatrix,'KFold',5,'Stratify',true);
Error using cvpartition (line 130)
CVPARTITION can have at most one optional argument
但是,在 MATLAB 版本 R2018a 及更高版本中,相同的代码可以正常工作:
I = randi(100,832,1);
predictionMatrix = (I>50);
c = cvpartition(predictionMatrix,'KFold',5,'Stratify',true)
c =
K-fold cross validation partition
NumObservations: 832
NumTestSets: 5
TrainSize: 666 665 665 666 666
TestSize: 166 167 167 166 166