matlab交叉验证分层,如何在MATLAB中对分类进行分层10倍交叉验证?(Howtop。。。

更新时间:2023-05-10 14:20:16 阅读: 评论:0

matlab交叉验证分层,如何在MATLAB中对分类进⾏分层10倍
交叉验证?(Howtop。。。
如何在MATLAB中对分类进⾏分层10倍交叉验证?(How to perform stratified 10 fold cross validation for classification in MATLAB?)
我通常的K-fold交叉验证的实现⾮常类似于:
K = 10;
CrossValIndices = crossvalind('Kfold', size(B,2), K);
for i = 1: K
display(['Cross validation, folds ' num2str(i)])
IndicesI = CrossValIndices==i;
TempInd = CrossValIndices;
TempInd(IndicesI) = [];
xTraining = B(:, CrossValIndices~=i);
tTrain = T_new1(:, CrossValIndices~=i);
xTest = B(:, CrossValIndices ==i);
tTest = T_new1(:, CrossValIndices ==i);
end
但是为了确保训练,测试和验证数据集具有相似的类别⽐例(例如,20个类别)。我想使⽤分层抽样技术。基本⽬的是避免类不平衡问题。我知道SMOTE技术但我想申请这个。
My implementation of usual K-fold cross-validation is pretty much like:
K = 10;
CrossValIndices = crossvalind('Kfold', size(B,2), K);
for i = 1: K
display(['Cross validation, folds ' num2str(i)])
IndicesI = CrossValIndices==i;
TempInd = CrossValIndices;
TempInd(IndicesI) = [];
xTraining = B(:, CrossValIndices~=i);
tTrain = T_new1(:, CrossValIndices~=i);
xTest = B(:, CrossValIndices ==i);
tTest = T_new1(:, CrossValIndices ==i);
end
But To ensure that the training, testing, and validating datat have similar proportions of class (e.g., 20 class).I want u stratified sampling technique.Basic purpo is to avoid class imbalance problem.I know about SMOTE technique but i want to apply this one.
更新时间:2019-11-21 09:39
最满意答案
您可以简单地使⽤crossvalind('Kfold', Group, K) ,其中Group是包含每个观察的类标签的向量。 这将导致每个组按⽐例丰富的集合。
You can simply u crossvalind('Kfold', Group, K), where Group is the vector containing the class label for each obrvation. This will lead to ts where each group is proportionally abundant.
2017-07-21
相关问答
您可以简单地使⽤crossvalind('Kfold', Group, K) ,其中Group是包含每个观察的类标签的向量。 这将导致每个组按⽐例丰富的集合。You can simply u crossvalind('Kfold', Group, K), where Group is the vector containing the class label for each obrvation. This will lead to ts where each group is pr
...
关于为每个⼦集执⾏代码,您可以将拟合放在循环中并存储结果,例如 % Sample the data
parm = [AT];
n = length(parm);
k = 10; % how many parts to u
allix = randperm(n); % all data indices, randomly ordered
numineach = ceil(n/k); % at least one part must have this ma
...
这是我对这个交叉验证的要求。 我使⽤魔法创建虚拟数据(10),我也随机创建标签。 想法在跟随,我们得到我们的数据和标签,并将它们与随机列结合起来。 考虑下⾯的虚拟代码。 >> data = magic(4)
data =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 1
5 1
>> dataRowNumber = size(data,1)
data
...
在查看混淆矩阵时,只有⼀个实例被错误分类。 这意味着它在所有折叠中也只发⽣过⼀次。
evaluate_Weka_classifier(iris_fit,numFolds = 10)$混淆矩阵 When looking at the confusion matrix, only one instance was miss-classified. This means that it also occured only 1 time in all the folds. evaluate_Weka_cl
...
我想说,在这种情况下,您希望对培训/验证过程有更多的控制权。 你有没有考虑分解更多的控制过程? 从cvpartition开始创建10倍交叉验证,然后分别对每个折叠进⾏操作。 I would say that in this ca you would like to have a bit more control over the
training/validation process. Have you considered breaking down the process for more
...
有⼏种⽅法可以写出来,其中⼀些⽐其他⽅法更容易理解。 Matlab⾮常适合写⼊,⽽1:3等表达式求值为[1,2,3] ,表达式1:0求值为空集。 因此,在不必使⽤if语句的情况下⽣成集合⾮常简单。 我开始循环: samples_per_digit=50;
block_sze=samples_per_digit/K;
for fold =1:K
test_ind = 1+(fold-1)*block_sze:fold*block_sze;
train_ind = [1:(fold-1
...
在libsvm中使⽤'-v 10'选项..它将为您进⾏交叉验证... u the '-v 10' option in libsvm.. it will do the cross validation
据我所知,Weka(和其他评估⽅法)中的交叉验证仅⽤于估计泛化误差。 也就是说,(隐式)假设是您希望将学习的模型与您未提供给Weka的数据(也称为“验证集”)⼀起使⽤。 因此,您获得的模型将对整个数据进⾏培训。 在交叉验证期间,它会训练和评估许多不同的模型(在您的情况下为10),以估计学习模型的概括程度。 您实际上并未看到这些模型 - 它们仅在内部使⽤。 未评估显⽰的模型。 As far as I know, the cross-validation in Weka (and the other
...
cvi是⼀个列表对象,所以cvi[-1]和cvi[1]是列表对象,然后你尝试使⽤列表对象得到x[cvi[-1]] ,这是没有意义的,因为列表对象可以是包含数字,字符,⽇期和其他列表的复杂对象。 订阅带有单个⽅括号的列表始终返回⼀个列表。 使⽤双⽅括号来获得成分,在这种情况下是向量。 > cvi[1] # this is a list with one element
$V1
[1] 101 78 231 82 211 239 20 201 294 276 181 168 207 240
...
以下在索引⽅⾯有点棘⼿(如果您使⽤像Pandas这样的东西会有所帮助),但在概念上很简单。 假设您
创建⼀个虚拟数据集,其中⾃变量只是id和class 。 此外,在此数据集中,删除重复的id条⽬。 对于交叉验证,在虚拟数据集上运⾏分层交叉验证。 在每次迭代时: 找出为⽕车和测试选择的id 返回原始数据集,并根据需要将属于id所有实例插⼊到训练集和测试集中。 这是因为: 如您所述,每个id都与⼀个标签相关联。 由于我们运⾏分层CV,每个类都按⽐例表⽰。 由于每个id仅出现在⽕车或测试集中(但不是两者)
...

本文发布于:2023-05-10 14:20:16,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/103391.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:S420MC
标签:验证   数据   交叉
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图