【问题标题】:Can I random select the amount of data from the matrix dataset?我可以从矩阵数据集中随机选择数据量吗?
【发布时间】:2019-03-16 16:15:52
【问题描述】:

我可以从数据集中随机固定行数吗?

例子

 A=[1 2 3 4; 
   5 6 7 8; 
   9 10 11 12; 
   13 14 15 16; 
   17 18 19 20];

我想随机选择训练数据集 3 行和随机选择测试数据集 2 行。

training_dataset= [1 2 3 4; 
                   13 14 15 16;
                   5 6 7 8;];

   testing_dataset= [ 9 10 11 12; 
                    17 18 19 20];

我只找到了数组中的随机数。

非常感谢

【问题讨论】:

  • edit您的问题澄清一下:您是要随机选择固定行数,还是随机选择行数? — 还请包括您迄今为止尝试过的内容。您一定通过 Google 或其他方式找到了一些解决方案。为什么那些不适合?添加这有助于缩小问题范围。谢谢!

标签: matlab matrix sampling


【解决方案1】:

此解决方案使用randpermsetdiff 命令。

indTrainRow = randperm(size(A,1),3)
indTestRow = setdiff(1:size(A,1),indTrainRow)

training_dataset = A(indTrainRow,:);
testing_dataset = A(indTestRow,:);

您也可以使用randsample,但这需要统计工具箱。

indTrainRow = randsample(1:size(A,1),3,'false') 

发布后,我发现了一些相关的帖子。我的错误是在回答之前没有找到这些。

相关帖子
Random selection of matrix columns
How can I divide/split up a matrix by rows between two other matrices?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-07
    • 2019-05-10
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 2016-11-08
    • 1970-01-01
    相关资源
    最近更新 更多