在Matlab中省去crossvalind [英] Leave one out crossvalind in Matlab

查看:84
本文介绍了在Matlab中省去crossvalind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经提取了用于男性和女性图片的HOG功能,现在,我正在尝试使用留一法" 对我的数据进行分类. 由于在Matlab中编写代码的标准方法是:

I have extracted HOG features for male and female pictures, now, I'm trying to use the Leave-one-out-method to classify my data. Due the standard way to write it in Matlab is:

[Train, Test] = crossvalind('LeaveMOut', N, M);

我应该写些什么而不是NM? 另外,我应该在循环内还是循环外编写上述代码语句? 这是我的代码,其中有用于男性(80张图像)和女性(80张图像)的培训文件夹,以及用于测试的另一文件夹(10张随机图像).

What I should write instead of N and M? Also, should I write above code statement inside or outside a loop? this is my code, where I have training folder for Male (80 images) and female (80 images), and another one for testing (10 random images).

for i = 1:10  
 [Train, Test] = crossvalind('LeaveMOut', N, 1);
 SVMStruct = svmtrain(Training_Set (Train), train_label (Train));
 Gender = svmclassify(SVMStruct, Test_Set_MF (Test)); 
end 

注意:

  • Training_Set:一个包含训练文件夹图像的HOG功能的数组.
  • Test_Set_MF:一个包含测试文件夹图像的HOG功能的数组.
  • N:训练文件夹中的图像总数.
  • SVM应该检测哪些图像是男性,哪些图像是女性.
  • Training_Set: an array consist of HOG features of training folder images.
  • Test_Set_MF: an array consist of HOG features of test folder images.
  • N: total number of images in training folder.
  • SVM should detect which images are male and which are female.

推荐答案

我将重点介绍如何将crossvalind用于留一法制方法.

I will focus on how to use crossvalind for the leave-one-out-method.

我假设您想在循环内选择随机集. N是数据向量的长度. MTest中随机选择的观测值的数量. M分别是Train中遗漏的观察数.这意味着您必须将N设置为训练集的长度.使用M,您可以指定要在Test-输出中分别指定多少个值,而在Train-输出中则要忽略的个数.

I assume you want to select random sets inside a loop. N is the length of your data vector. M is the number of randomly selected observations in Test. Respectively M is the number of observations left out in Train. This means you have to set N to the length of your training-set. With M you can specify how many values you want in your Test-output, respectively you want to left out in your Train-output.

这里是一个示例,从数据集中选择M=2个观测值.

Here is an example, selecting M=2 observations out of the dataset.

dataset = [1 2 3 4 5 6 7 8 9 10];
N = length(dataset);
M = 2;

for i = 1:5
    [Train, Test] = crossvalind('LeaveMOut', N, M);
    % do whatever you want with Train and Test
    dataset(Test) % display the test-entries
end

这将输出:(这是随机生成的,因此不会有相同的结果)

ans =
     1     9
ans =
     6     8
ans =
     7    10
ans =
     4     5
ans =
     4     7


根据


As you have it in your code according to this post, you need to adjust it for a matrix of features:

Training_Set = rand(10,3);     % 10 samples with 3 features each

N = size(Training_Set,1);
M = 2;

for i = 1:5
    [Train, Test] = crossvalind('LeaveMOut', N, 2);
    Training_Set(Train,:) % displays the data to train
end

这篇关于在Matlab中省去crossvalind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆