在Matlab中省略交叉验证算法

编程入门 行业动态 更新时间:2024-10-23 04:58:09
本文介绍了在Matlab中省略交叉验证算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人知道如何在MATLAB中进行留一法交叉验证吗?我需要LOOCV算法进行数据分类.举个例子.我有10个训练集,我想从训练集中拿出一个进行测试.因此,就像1 =测试和9进行训练,然后再次进行直到最后一次数据训练为止.

Do someone know how to perform Leave one out cross validation in MATLAB?? I need LOOCV algorithm for data classification. So for example . I have the number of training set 10 , and I want to take out one from training set for testing. So, it's like 1 = testing and 9 for training, and do it again until the last data training.

如果我们接受这种癌症这样的数据培训,而没有癌症,该怎么办?

How about if we have data training like this cancer and no cancer:

[C,F] = training('D:\cancer\',... 'D:\nocancer\');

推荐答案

这就是我要做的事情:

// Initialize result matrix Results = zeros(size(Datas,1),2); // Validate classifier settings with leave-one-out procedure for k=1:size(Datas,1) // Extract sample ind = Datas(k,:); // Copy the database Datas_mod = Datas; // Copy the classes vector Classes_mod = Classes; // Keep the sample real class Results(k,2) = Classes(k); // Remove sample from database Datas_mod(k,:) = []; // Remove sample from class vector Classes_mod(k) = []; // Execute the classification algorithm [Individu,MxD(k)] = knn(ind(1,1:size(ind,2)),Datas_mod,Classes_mod,5,700); // Keep the class found by the classifier for the current sample Results(k,1) = Individu(1,size(Individu,2)); end // Confusion matrix CM = nan_confusionmat(Results(:,1),Results(:,2)) // Scilab function, find your own

只需用您使用的分类器替换knn即可.希望有帮助.

Just replace knn by whichever classifier you're using. Hope this help.

更多推荐

在Matlab中省略交叉验证算法

本文发布于:2023-11-03 15:01:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555421.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!