split training data and testing data
显示 更早的评论
Hello i have a 54000 x 10 matrix i want to split it 70% training and 30% testing whats the easiest way to do that ?
1 个评论
Delvan Mjomba
2019-6-6
Use the Randperm command to ensure random splitting. Its very easy.
for example:
if you have 150 items to split for training and testing proceed as below:
Indices=randperm(150);
Trainingset=<data file name>(indices(1:105),:);
Testingset=<data file name>(indices(106:end),:);
采纳的回答
更多回答(4 个)
Gilbert Temgoua
2022-4-19
编辑:Gilbert Temgoua
2022-4-20
I find dividerand very straightforward, see below:
% randomly select indexes to split data into 70%
% training set, 0% validation set and 30% test set.
[train_idx, ~, test_idx] = dividerand(54000, 0.7, 0,
0.3);
% slice training data with train indexes
%(take training indexes in all 10 features)
x_train = x(train_idx, :);
% select test data
x_test = x(test_idx, :);
1 个评论
uma
2022-4-28
how to split the data into trainx trainy testx testy format but both trainx trainy should have first dimension same also for testx testy should have first dimension same.Example i have a dataset 1000*9 . trainx should contain 1000*9, trainy should contain 1000*1, testx should contain 473*9 and texty should contain473*1.
Vrushal Shah
2019-3-14
3 个投票
If we want to Split the data set in Training and Testing Phase what is the best option to do that ?
Jere Thayo
2022-10-28
0 个投票
what if both training and testing are already in files, i.e X_train.mat, y_train.mat, x_test.mat and y_test.mat
Syed Iftikhar
2023-1-1
0 个投票
I have input variable name 's' in which i have data only in columns. The size is 1000000. I want to split that for 20% test. So i can save that data in some other variable. because i will gonna use that test data in some python script. Any Idea how to do this?
类别
在 帮助中心 和 File 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!