randomly divide a matrix

조회 수: 4 (최근 30일)
baran
baran 2017년 5월 21일
댓글: Star Strider 2021년 6월 6일
hi, i have a 16435*25 matrix that name is input, i want to randomly divided it in 2 parts: one for train and another for validate data, that 70% of its rows randomly selected as train matrix (i.e 11504*25 matrix) and 30% of its rows randomly selected as validate matrix (i.e 4930*25), how can i do this? thanks a lot

채택된 답변

Star Strider
Star Strider 2017년 5월 21일
For your matrix:
row_idx = randperm(16435, 11504)';
To illustrate:
example = randperm(10, 7)'
example =
5
8
2
4
7
3
10
  댓글 수: 4
Onurcan BAL
Onurcan BAL 2021년 6월 6일
Thanks for both question and this explanation!
Star Strider
Star Strider 2021년 6월 6일
My pleasure!
(A Vote would be appreciated!)
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

MathReallyWorks
MathReallyWorks 2017년 5월 21일
편집: MathReallyWorks 2017년 5월 21일
Hello Dear,
Use this code. I've generated a random matrix of the same order that you want. I have randomized all the rows of matrix and then I'm selecting first 11504 rows for training and rest for validation. I hope it will be helpful.
orderedArray = rand(16435,25); % Random Data %You can use your data here
shuffledArray = orderedArray(randperm(size(orderedArray,1)),:); %Randomizing the rows of matrix
t=zeros(11504,25); % Size of Train Data
v=zeros(4930,25); % Size of Validate Data
for i=1:11504
t(i,:) = shuffledArray(i,:);
end
j=1;
for i=11541:16435
v(j,:) = shuffledArray(i,:);
j=j+1;
end
Type whos t and whos v on command window, you will get to know the dimensions of train and validate data matrices.

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by